Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2007 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time.base; import java.io.Serializable; import org.joda.time.Chronology; import org.joda.time.DateTimeUtils; import org.joda.time.Duration; import org.joda.time.DurationFieldType; import org.joda.time.MutablePeriod; import org.joda.time.PeriodType; import org.joda.time.ReadWritablePeriod; import org.joda.time.ReadableDuration; import org.joda.time.ReadableInstant; import org.joda.time.ReadablePartial; import org.joda.time.ReadablePeriod; import org.joda.time.chrono.ISOChronology; import org.joda.time.convert.ConverterManager; import org.joda.time.convert.PeriodConverter; import org.joda.time.field.FieldUtils; /** * BasePeriod is an abstract implementation of ReadablePeriod that stores * data in a <code>PeriodType</code> and an <code>int[]</code>. * <p> * This class should generally not be used directly by API users. * The {@link ReadablePeriod} interface should be used when different * kinds of period objects are to be referenced. * <p> * BasePeriod subclasses may be mutable and not thread-safe. * * @author Brian S O'Neill * @author Stephen Colebourne * @since 1.0 */ public abstract class BasePeriod extends AbstractPeriod implements ReadablePeriod, Serializable { /** Serialization version */ private static final long serialVersionUID = -2110953284060001145L; /** The type of period */ private PeriodType iType; /** The values */ private int[] iValues; //----------------------------------------------------------------------- /** * Creates a period from a set of field values. * * @param years amount of years in this period, which must be zero if unsupported * @param months amount of months in this period, which must be zero if unsupported * @param weeks amount of weeks in this period, which must be zero if unsupported * @param days amount of days in this period, which must be zero if unsupported * @param hours amount of hours in this period, which must be zero if unsupported * @

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>param minutes amount of minutes in this period, which must be zero if unsupported * @param seconds amount of seconds in this period, which must be zero if unsupported * @param millis amount of milliseconds in this period, which must be zero if unsupported * @param type which set of fields this period supports * @throws IllegalArgumentException if period type is invalid * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected BasePeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis, PeriodType type) { super(); type = checkPeriodType(type); iType = type; setPeriodInternal(years, months, weeks, days, hours, minutes, seconds, millis); // internal method } /** * Creates a period from the given interval endpoints. * * @param startInstant interval start, in milliseconds * @param endInstant interval end, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid */ protected BasePeriod(long startInstant, long endInstant, PeriodType type, Chronology chrono) { super(); type = checkPeriodType(type); chrono = DateTimeUtils.getChronology(chrono); iType = type; iValues = chrono.get(this, startInstant, endInstant); } /** * Creates a period from the given interval endpoints. * * @param startInstant interval start, null means now * @param endInstant interval end, null means now * @param type which set of fields this period supports, null means standard * @throws IllegalArgumentException if period type is invalid */ protected BasePeriod(ReadableInstant startInstant, ReadableInstant endInstant, PeriodType type) { super(); type = checkPeriodType(type); if (startInstant == null && endInstant == null) { iType = type; iValues = new int[size()]; } else { long startMillis = DateTimeUtils.getInstantMillis(startInstant); long endMillis = DateTimeUtils.getInstantMillis(endInstant); Chronology chrono = DateTimeUtils.getIntervalChronology(startInstant, endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } } /** * Creates a period from the given duration and end point. * <p> * The two partials must contain the same fields, thus you can * specify two <code>LocalDate</code> objects, or two <code>LocalTime</code> * objects, but not one of each. * As these are Partial objects, time zones have no effect on the result. * <p> * The two partials must also both be contiguous - see * {@link DateTimeUtils#isContiguous(ReadablePartial)} for a * definition. Both <code>LocalDate</code> and <code>LocalTime</code> are contiguous.

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * * @param start the start of the period, must not be null * @param end the end of the period, must not be null * @param type which set of fields this period supports, null means standard * @throws IllegalArgumentException if the partials are null or invalid * @since 1.1 */ protected BasePeriod(ReadablePartial start, ReadablePartial end, PeriodType type) { super(); if (start == null || end == null) { throw new IllegalArgumentException("ReadablePartial objects must not be null"); } if (start instanceof BaseLocal && end instanceof BaseLocal && start.getClass() == end.getClass()) { // for performance type = checkPeriodType(type); long startMillis = ((BaseLocal) start).getLocalMillis(); long endMillis = ((BaseLocal) end).getLocalMillis(); Chronology chrono = start.getChronology(); chrono = DateTimeUtils.getChronology(chrono); iType = type; iValues = chrono.get(this, startMillis, endMillis); } else { if (start.size() != end.size()) { throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields"); } for (int i = 0, isize = start.size(); i < isize; i++) { if (start.getFieldType(i) != end.getFieldType(i)) { throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields"); } } if (DateTimeUtils.isContiguous(start) == false) { throw new IllegalArgumentException("ReadablePartial objects must be contiguous"); } iType = checkPeriodType(type); Chronology chrono = DateTimeUtils.getChronology(start.getChronology()).withUTC(); iValues = chrono.get(this, chrono.set(start, 0L), chrono.set(end, 0L)); } } /** * Creates a period from the given start point and duration. * * @param startInstant the interval start, null means now * @param duration the duration of the interval, null means zero-length * @param type which set of fields this period supports, null means standard */ protected BasePeriod(ReadableInstant startInstant, ReadableDuration duration, PeriodType type) { super(); type = checkPeriodType(type); long startMillis = DateTimeUtils.getInstantMillis(startInstant); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = FieldUtils.safeAdd(startMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(startInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given duration and end point. * * @param duration the duration of the interval, null means zero-length * @param endInstant the interval end, null means now * @param type which set of fields this period supports, null means standard */ protected BasePeriod

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>(ReadableDuration duration, ReadableInstant endInstant, PeriodType type) { */ protected BasePeriod(long duration, PeriodType type, Chronology chrono) { super(); type = checkPeriodType(type); chrono = DateTimeUtils.getChronology(chrono); iType = type; iValues = chrono.get(this, duration); } /** * Creates a new period based on another using the {@link ConverterManager}. * * @param period the period to convert * @param type which set of fields this period supports, null means use type from object * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period is invalid * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected BasePeriod(Object period, PeriodType type, Chronology chrono) { super(); PeriodConverter converter = ConverterManager.getInstance().getPeriodConverter(period); type = (type == null ? converter.getPeriodType(period) : type); type = checkPeriodType(type); iType = type; if (this instanceof ReadWritablePeriod) { iValues = new int[size()]; chrono = DateTimeUtils.getChronology(chrono); converter.setInto((ReadWritablePeriod) this, period, chrono); } else { iValues = new MutablePeriod(period, type, chrono).getValues(); } } /** * Constructor used when we trust ourselves. * Do not expose publically. * * @param values the values to use, not null, not cloned * @param type which set of fields this period supports, not null */ protected BasePeriod(int[] values, PeriodType type) { super(); iType = type; iValues = values; } //----------------------------------------------------------------------- /** * Validates a period type, converting nulls to a default value and * checking the type is suitable for this instance. * * @param type the type to check, may be null * @return the validated type to use, not null * @throws IllegalArgumentException if the period type is invalid */ protected PeriodType checkPeriodType(PeriodType type) { return DateTimeUtils.getPeriodType(type); } //----------------------------------------------------------------------- /** * Gets the period type. * * @return the period type */ public PeriodType getPeriodType() { return iType; } //----------------------------------------------------------------------- /** * Gets the number of fields that this period supports. * * @return the number of fields supported */ public int size() { return iType.size(); } /** * Gets the field type at the specified index. * * @param index the index to retrieve * @return the field at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public DurationFieldType getFieldType(int index) { return iType.getFieldType(index); } /** * Gets the value at the specified index. * * @param index the index to retrieve * @return the value of

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> the field at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public int getValue(int index) { return iValues[index]; } //----------------------------------------------------------------------- /** * Gets the total millisecond duration of this period relative to a start instant. * <p> * This method adds the period to the specified instant in order to * calculate the duration. * <p> * An instant must be supplied as the duration of a period varies. * For example, a period of 1 month could vary between the equivalent of * 28 and 31 days in milliseconds due to different length months. * Similarly, a day can vary at Daylight Savings cutover, typically between * 23 and 25 hours. * * @param startInstant the instant to add the period to, thus obtaining the duration * @return the total length of the period as a duration relative to the start instant * @throws ArithmeticException if the millis exceeds the capacity of the duration */ public Duration toDurationFrom(ReadableInstant startInstant) { long startMillis = DateTimeUtils.getInstantMillis(startInstant); Chronology chrono = DateTimeUtils.getInstantChronology(startInstant); long endMillis = chrono.add(this, startMillis, 1); return new Duration(startMillis, endMillis); } /** * Gets the total millisecond duration of this period relative to an * end instant. * <p> * This method subtracts the period from the specified instant in order * to calculate the duration. * <p> * An instant must be supplied as the duration of a period varies. * For example, a period of 1 month could vary between the equivalent of * 28 and 31 days in milliseconds due to different length months. * Similarly, a day can vary at Daylight Savings cutover, typically between * 23 and 25 hours. * * @param endInstant the instant to subtract the period from, thus obtaining the duration * @return the total length of the period as a duration relative to the end instant * @throws ArithmeticException if the millis exceeds the capacity of the duration */ public Duration toDurationTo(ReadableInstant endInstant) { long endMillis = DateTimeUtils.getInstantMillis(endInstant); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); long startMillis = chrono.add(this, endMillis, -1); return new Duration(startMillis, endMillis); } //----------------------------------------------------------------------- /** * Checks whether a field type is supported, and if so adds the new value * to the relevent index in the specified array. * * @param type the field type * @param values the array to update * @param newValue the new value to store if successful */ private void checkAndUpdate(DurationFieldType type, int[] values, int newValue) { int index = indexOf(type); if (index == -1) { if (newValue != 0) { throw new IllegalArgumentException

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>( "Period does not support field '" + type.getName() + "'"); } } else { values[index] = newValue; } } //----------------------------------------------------------------------- /** * Sets all the fields of this period from another. * * @param period the period to copy from, not null * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected void setPeriod(ReadablePeriod period) { if (period == null) { setValues(new int[size()]); } else { setPeriodInternal(period); } } /** * Private method called from constructor. */ private void setPeriodInternal(ReadablePeriod period) { int[] newValues = new int[size()]; for (int i = 0, isize = period.size(); i < isize; i++) { DurationFieldType type = period.getFieldType(i); int value = period.getValue(i); checkAndUpdate(type, newValues, value); } iValues = newValues; } /** * Sets the eight standard the fields in one go. * * @param years amount of years in this period, which must be zero if unsupported * @param months amount of months in this period, which must be zero if unsupported * @param weeks amount of weeks in this period, which must be zero if unsupported * @param days amount of days in this period, which must be zero if unsupported * @param hours amount of hours in this period, which must be zero if unsupported * @param minutes amount of minutes in this period, which must be zero if unsupported * @param seconds amount of seconds in this period, which must be zero if unsupported * @param millis amount of milliseconds in this period, which must be zero if unsupported * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected void setPeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis) { setPeriodInternal(years, months, weeks, days, hours, minutes, seconds, millis); } /** * Private method called from constructor. */ private void setPeriodInternal(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis) { int[] newValues = new int[size()]; checkAndUpdate(DurationFieldType.years(), newValues, years); checkAndUpdate(DurationFieldType.months(), newValues, months); checkAndUpdate(DurationFieldType.weeks(), newValues, weeks); checkAndUpdate(DurationFieldType.days(), newValues, days); checkAndUpdate(DurationFieldType.hours(), newValues, hours); checkAndUpdate(DurationFieldType.minutes(), newValues, minutes); checkAndUpdate(DurationFieldType.seconds(), newValues, seconds); checkAndUpdate(DurationFieldType.millis(), newValues, millis); iValues = newValues; } //----------------------------------------------------------------------- /** * Sets the value of a field in this period. * * @param field the field to set * @param value the value to set

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * @throws IllegalArgumentException if field is is null or not supported. */ protected void setField(DurationFieldType field, int value) { setFieldInto(iValues, field, value); } /** * Sets the value of a field in this period. * * @param values the array of values to update * @param field the field to set * @param value the value to set * @throws IllegalArgumentException if field is null or not supported. */ protected void setFieldInto(int[] values, DurationFieldType field, int value) { int index = indexOf(field); if (index == -1) { if (value != 0 || field == null) { throw new IllegalArgumentException( "Period does not support field '" + field + "'"); } } else { values[index] = value; } } /** * Adds the value of a field in this period. * * @param field the field to set * @param value the value to set * @throws IllegalArgumentException if field is is null or not supported. */ protected void addField(DurationFieldType field, int value) { addFieldInto(iValues, field, value); } /** * Adds the value of a field in this period. * * @param values the array of values to update * @param field the field to set * @param value the value to set * @throws IllegalArgumentException if field is is null or not supported. */ protected void addFieldInto(int[] values, DurationFieldType field, int value) { int index = indexOf(field); if (index == -1) { if (value != 0 || field == null) { throw new IllegalArgumentException( "Period does not support field '" + field + "'"); } } else { values[index] = FieldUtils.safeAdd(values[index], value); } } /** * Merges the fields from another period. * * @param period the period to add from, not null * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected void mergePeriod(ReadablePeriod period) { if (period != null) { iValues = mergePeriodInto(getValues(), period); } } /** * Merges the fields from another period. * * @param values the array of values to update * @param period the period to add from, not null * @return the updated values * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected int[] mergePeriodInto(int[] values, ReadablePeriod period) { for (int i = 0, isize = period.size(); i < isize; i++) { DurationFieldType type = period.getFieldType(i); int value = period.getValue(i); checkAndUpdate(type, values, value); } return values; } /** * Adds the fields from another period. * * @param period the period to add from, not null * @throws IllegalArgumentException if an

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> unsupported field's value is non-zero */ protected void addPeriod(ReadablePeriod period) { if (period != null) { iValues = addPeriodInto(getValues(), period); } } /** * Adds the fields from another period. * * @param values the array of values to update * @param period the period to add from, not null * @return the updated values * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected int[] addPeriodInto(int[] values, ReadablePeriod period) { for (int i = 0, isize = period.size(); i < isize; i++) { DurationFieldType type = period.getFieldType(i); int value = period.getValue(i); if (value != 0) { int index = indexOf(type); if (index == -1) { throw new IllegalArgumentException( "Period does not support field '" + type.getName() + "'"); } else { values[index] = FieldUtils.safeAdd(getValue(index), value); } } } return values; } //----------------------------------------------------------------------- /** * Sets the value of the field at the specifed index. * * @param index the index * @param value the value to set * @throws IndexOutOfBoundsException if the index is invalid */ protected void setValue(int index, int value) { iValues[index] = value; } /** * Sets the values of all fields. * * @param values the array of values */ protected void setValues(int[] values) { iValues = values; } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> second to use * @param millisOfSecond millisecond to use * @return millisecond instant from 1970-01-01T00:00:00Z */ public long getDateTimeMillis(long instant, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) throws IllegalArgumentException { instant = hourOfDay().set(instant, hourOfDay); instant = minuteOfHour().set(instant, minuteOfHour); instant = secondOfMinute().set(instant, secondOfMinute); return millisOfSecond().set(instant, millisOfSecond); } //----------------------------------------------------------------------- /** * Validates whether the fields stored in a partial instant are valid. * <p> * This implementation uses {@link DateTimeField#getMinimumValue(ReadablePartial, int[])} * and {@link DateTimeField#getMaximumValue(ReadablePartial, int[])}. * * @param partial the partial instant to validate * @param values the values to validate, not null * @throws IllegalArgumentException if the instant is invalid */ public void validate(ReadablePartial partial, int[] values) { // check values in standard range, catching really stupid cases like -1 // this means that the second check will not hit trouble int size = partial.size(); for (int i = 0; i < size; i++) { int value = values[i]; DateTimeField field = partial.getField(i); if (value < field.getMinimumValue()) { throw new IllegalFieldValueException (field.getType(), new Integer(value), new Integer(field.getMinimumValue()), null); } if (value > field.getMaximumValue()) { throw new IllegalFieldValueException (field.getType(), new Integer(value), null, new Integer(field.getMaximumValue())); } } // check values in specific range, catching really odd cases like 30th Feb for (int i = 0; i < size; i++) { int value = values[i]; DateTimeField field = partial.getField(i); if (value < field.getMinimumValue(partial, values)) { throw new IllegalFieldValueException (field.getType(), new Integer(value), new Integer(field.getMinimumValue(partial, values)), null); } if (value > field.getMaximumValue(partial, values)) { throw new IllegalFieldValueException (field.getType(), new Integer(value), null, new Integer(field.getMaximumValue(partial, values))); } } } /** * Gets the values of a partial from an instant. * * @param partial the partial instant to use * @param instant the instant to query * @return the values of the partial extracted from the instant */ public int[] get(ReadablePartial partial, long instant) { int size = partial.size(); int[] values = new int[size]; for (int i = 0; i < size; i++) { values[i] = partial.getFieldType(i).

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>getField(this).get(instant); } return values; } /** * Sets the partial into the instant. * * @param partial the partial instant to use * @param instant the instant to update * @return the updated instant */ public long set(ReadablePartial partial, long instant) { for (int i = 0, isize = partial.size(); i < isize; i++) { instant = partial.getFieldType(i).getField(this).set(instant, partial.getValue(i)); } return instant; } //----------------------------------------------------------------------- /** * Gets the values of a period from an interval. * * @param period the period instant to use * @param startInstant the start instant of an interval to query * @param endInstant the start instant of an interval to query * @return the values of the period extracted from the interval */ public int[] get(ReadablePeriod period, long startInstant, long endInstant) { int size = period.size(); int[] values = new int[size]; if (startInstant != endInstant) { for (int i = 0; i < size; i++) { DurationField field = period.getFieldType(i).getField(this); int value = field.getDifference(endInstant, startInstant); startInstant = field.add(startInstant, value); values[i] = value; } } return values; } /** * Gets the values of a period from an interval. * * @param period the period instant to use * @param duration the duration to query * @return the values of the period extracted from the duration */ public int[] get(ReadablePeriod period, long duration) { int size = period.size(); int[] values = new int[size]; if (duration != 0) { long current = 0; for (int i = 0; i < size; i++) { DurationField field = period.getFieldType(i).getField(this); if (field.isPrecise()) { int value = field.getDifference(duration, current); current = field.add(current, value); values[i] = value; } } } return values; } /** * Adds the period to the instant, specifying the number of times to add. * * @param period the period to add, null means add nothing * @param instant the instant to add to * @param scalar the number of times to add * @return the updated instant */ public long add(ReadablePeriod period, long instant, int scalar) { if (scalar != 0 && period != null) { for (int i = 0, isize = period.size(); i < isize; i++) { long value = period.getValue(i); // use long to allow for multiplication (fits OK) if (value != 0) { instant = period.getFieldType(i).getField(this).add(instant, value * scalar);

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>, test.getSeconds()); assertEquals(8, test.getMillis()); } finally { DateTimeZone.setDefault(zone); } } //----------------------------------------------------------------------- public void testToPeriod_PeriodType() { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; Duration test = new Duration(length); Period result = test.toPeriod(PeriodType.standard().withMillisRemoved()); assertEquals(new Period(test, PeriodType.standard().withMillisRemoved()), result); assertEquals(new Period(test.getMillis(), PeriodType.standard().withMillisRemoved()), result); } //----------------------------------------------------------------------- public void testToPeriod_Chronology() { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; Duration test = new Duration(length); Period result = test.toPeriod(ISOChronology.getInstanceUTC()); assertEquals(new Period(test, ISOChronology.getInstanceUTC()), result); assertEquals(new Period(test.getMillis(), ISOChronology.getInstanceUTC()), result); } //----------------------------------------------------------------------- public void testToPeriod_PeriodType_Chronology() { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; Duration test = new Duration(length); Period result = test.toPeriod(PeriodType.standard().withMillisRemoved(), ISOChronology.getInstanceUTC()); assertEquals(new Period(test, PeriodType.standard().withMillisRemoved(), ISOChronology.getInstanceUTC()), result); assertEquals(new Period(test.getMillis(), PeriodType.standard().withMillisRemoved(), ISOChronology.getInstanceUTC()), result); } //----------------------------------------------------------------------- public void testToPeriodFrom() { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTime

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>Constants.MILLIS_PER_SECOND + 8L; Duration test = new Duration(length); DateTime dt = new DateTime(2004, 6, 9, 0, 0, 0, 0); Period result = test.toPeriodFrom(dt); assertEquals(new Period(dt, test), result); } //----------------------------------------------------------------------- public void testToPeriodFrom_PeriodType() { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; Duration test = new Duration(length); DateTime dt = new DateTime(2004, 6, 9, 0, 0, 0, 0); Period result = test.toPeriodFrom(dt, PeriodType.standard().withMillisRemoved()); assertEquals(new Period(dt, test, PeriodType.standard().withMillisRemoved()), result); } //----------------------------------------------------------------------- public void testToPeriodTo() { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; Duration test = new Duration(length); DateTime dt = new DateTime(2004, 6, 9, 0, 0, 0, 0); Period result = test.toPeriodTo(dt); assertEquals(new Period(test, dt), result); } //----------------------------------------------------------------------- public void testToPeriodTo_PeriodType() { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; Duration test = new Duration(length); DateTime dt = new DateTime(2004, 6, 9, 0, 0, 0, 0); Period result = test.toPeriodTo(dt, PeriodType.standard().withMillisRemoved()); assertEquals(new Period(test, dt, PeriodType.standard().withMillisRemoved()), result); } //----------------------------------------------------------------------- public void testToIntervalFrom() { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.M

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2005 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time.chrono; import org.joda.time.DateTimeFieldType; import org.joda.time.DurationField; import org.joda.time.ReadablePartial; import org.joda.time.field.PreciseDurationDateTimeField; /** * Provides time calculations for the day of the month component of time. * * @author Guy Allard * @author Stephen Colebourne * @author Brian S O'Neill * @since 1.1, refactored from GJDayOfMonthDateTimeField */ final class BasicDayOfMonthDateTimeField extends PreciseDurationDateTimeField { private static final long serialVersionUID = -4677223814028011723L; private final BasicChronology iChronology; /** * Restricted constructor. */ BasicDayOfMonthDateTimeField(BasicChronology chronology, DurationField days) { super(DateTimeFieldType.dayOfMonth(), days); iChronology = chronology; } //----------------------------------------------------------------------- public int get(long instant) { return iChronology.getDayOfMonth(instant); } public DurationField getRangeDurationField() { return iChronology.months(); } public int getMinimumValue() { return 1; } public int getMaximumValue() { return iChronology.getDaysInMonthMax(); } public int getMaximumValue(long instant) { return iChronology.getDaysInMonthMax(instant); } public int getMaximumValue(ReadablePartial partial) { if (partial.isSupported(DateTimeFieldType.monthOfYear())) { int month = partial.get(DateTimeFieldType.monthOfYear()); if (partial.isSupported(DateTimeFieldType.year())) { int year = partial.get(DateTimeFieldType.year()); return iChronology.getDaysInYearMonth(year, month); } return iChronology.getDaysInMonthMax(month); } return getMaximumValue(); } public int getMaximumValue(ReadablePartial partial, int[] values) { int size = partial.size(); for (int i = 0; i < size; i++) { if (partial.getFieldType(i) == DateTimeFieldType.monthOfYear()) { int month = values[i]; for

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> (int j = 0; j < size; j++) { if (partial.getFieldType(j) == DateTimeFieldType.year()) { int year = values[j]; return iChronology.getDaysInYearMonth(year, month); } } return iChronology.getDaysInMonthMax(month); } } return getMaximumValue(); } protected int getMaximumValueForSet(long instant, int value) { return iChronology.getDaysInMonthMaxForSet(instant, value); } /** * Serialization singleton */ private Object readResolve() { return iChronology.dayOfMonth(); } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> private long TEST_TIME_NOW = (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY; private DateTimeZone originalDateTimeZone = null; private TimeZone originalTimeZone = null; private Locale originalLocale = null; public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static TestSuite suite() { return new TestSuite(TestPeriod_Constructors.class); } public TestPeriod_Constructors(String name) { super(name); } protected void setUp() throws Exception { DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW); originalDateTimeZone = DateTimeZone.getDefault(); originalTimeZone = TimeZone.getDefault(); originalLocale = Locale.getDefault(); DateTimeZone.setDefault(LONDON); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Locale.setDefault(Locale.UK); } protected void tearDown() throws Exception { DateTimeUtils.setCurrentMillisSystem(); DateTimeZone.setDefault(originalDateTimeZone); TimeZone.setDefault(originalTimeZone); Locale.setDefault(originalLocale); originalDateTimeZone = null; originalTimeZone = null; originalLocale = null; } //----------------------------------------------------------------------- public void testConstants() throws Throwable { Period test = Period.ZERO; assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- public void testParse_noFormatter() throws Throwable { assertEquals(new Period(1, 2, 3, 4, 5, 6, 7, 890), Period.parse("P1Y2M3W4DT5H6M7.890S")); } //----------------------------------------------------------------------- public void testConstructor1() throws Throwable { Period test = new Period(); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_long1() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> Period test = new Period(length); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((4 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long2() throws Throwable { long length = 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long3() throws Throwable { long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; Period test = new Period(length); assertEquals(PeriodType.standard(), test.getPeriodType()); // only time fields are precise in AllType assertEquals(0, test.getYears()); // (4 + (3 * 7) + (2 * 30) + 365) == 450 assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((450 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long_fixedZone() throws Throwable { DateTimeZone zone = DateTimeZone.getDefault(); try { DateTimeZone.setDefault(DateTimeZone.forOffsetHours(2)); long length = (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; Period test = new Period(length);

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> assertEquals(PeriodType.standard(), test.getPeriodType()); // only time fields are precise in AllType assertEquals(0, test.getYears()); // (4 + (3 * 7) + (2 * 30) + 365) == 450 assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((450 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } finally { DateTimeZone.setDefault(zone); } } //----------------------------------------------------------------------- public void testConstructor_long_PeriodType1() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, (PeriodType) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((4 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long_PeriodType2() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, PeriodType.millis()); assertEquals(PeriodType.millis(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(length, test.getMillis()); } public void testConstructor_long_PeriodType3() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, PeriodType.dayTime()); assertEquals(PeriodType.dayTime(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>(0, test.getDays()); assertEquals((4 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long_PeriodType4() throws Throwable { long length = 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, PeriodType.standard().withMillisRemoved()); assertEquals(PeriodType.standard().withMillisRemoved(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_long_Chronology1() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, ISOChronology.getInstance()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((4 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long_Chronology2() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, ISOChronology.getInstanceUTC()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(4, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long_Chronology3() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.M

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>ILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, (Chronology) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((4 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_long_PeriodType_Chronology1() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, PeriodType.time().withMillisRemoved(), ISOChronology.getInstance()); assertEquals(PeriodType.time().withMillisRemoved(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((4 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_long_PeriodType_Chronology2() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, PeriodType.standard(), ISOChronology.getInstanceUTC()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(4, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long_PeriodType_Chronology3() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, PeriodType.standard(), (Chronology) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((4 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_long_PeriodType_Chronology4() throws Throwable { long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5 * DateTimeConstants.MILLIS_PER_HOUR + 6 * DateTimeConstants.MILLIS_PER_MINUTE + 7 * DateTimeConstants.MILLIS_PER_SECOND + 8; Period test = new Period(length, (PeriodType) null, (Chronology) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals((4 * 24) + 5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } //----------------------------------------------------------------------- /** * Test constructor (4ints) */ public void testConstructor_4int1() throws Throwable { Period test = new Period(5, 6, 7, 8); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } //----------------------------------------------------------------------- /** * Test constructor (8ints) */ public void testConstructor_8int1() throws Throwable { Period test = new Period(1, 2, 3, 4, 5, 6, 7, 8); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(2, test.getMonths()); assertEquals(3, test.getWeeks()); assertEquals(4, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } //----------------------------------------------------------------------- /** * Test constructor (8ints) */ public void testConstructor_8int__PeriodType1() throws Throwable { Period test = new Period(1, 2, 3, 4, 5, 6, 7, 8, null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(2, test.getMonths()); assertEquals(3, test

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>.getWeeks()); assertEquals(4, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_8int__PeriodType2() throws Throwable { Period test = new Period(0, 0, 0, 0, 5, 6, 7, 8, PeriodType.dayTime()); assertEquals(PeriodType.dayTime(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } public void testConstructor_8int__PeriodType3() throws Throwable { try { new Period(1, 2, 3, 4, 5, 6, 7, 8, PeriodType.dayTime()); fail(); } catch (IllegalArgumentException ex) {} } //----------------------------------------------------------------------- public void testConstructor_long_long1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Period test = new Period(dt1.getMillis(), dt2.getMillis()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_long_long2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1); Period test = new Period(dt1.getMillis(), dt2.getMillis()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(1, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_long_long_PeriodType1() throws Throwable { DateTime dt1 = new DateTime(200

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>4, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Period test = new Period(dt1.getMillis(), dt2.getMillis(), (PeriodType) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_long_long_PeriodType2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2004, 7, 10, 1, 1, 1, 1); Period test = new Period(dt1.getMillis(), dt2.getMillis(), PeriodType.dayTime()); assertEquals(PeriodType.dayTime(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(31, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_long_long_PeriodType3() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2004, 6, 9, 1, 1, 1, 1); Period test = new Period(dt1.getMillis(), dt2.getMillis(), PeriodType.standard().withMillisRemoved()); assertEquals(PeriodType.standard().withMillisRemoved(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testToPeriod_PeriodType3() { DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10); DateTime dt2 = new DateTime(2005, 6, 9, 12, 14, 16, 18); Period test = new Period(dt1.getMillis(), dt2.getMillis(), PeriodType.yearWeekDayTime

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>()); assertEquals(PeriodType.yearWeekDayTime(), test.getPeriodType()); assertEquals(1, test.getYears()); // tests using years and not weekyears assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(5, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(7, test.getSeconds()); assertEquals(8, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_long_long_Chronology1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, CopticChronology.getInstance()); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, CopticChronology.getInstance()); Period test = new Period(dt1.getMillis(), dt2.getMillis(), CopticChronology.getInstance()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_long_long_Chronology2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Period test = new Period(dt1.getMillis(), dt2.getMillis(), (Chronology) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_long_long_PeriodType_Chronology1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, CopticChronology.getInstance()); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, CopticChronology.getInstance()); Period test = new Period(dt1.getMillis(), dt2.getMillis(), (PeriodType) null, CopticChronology.getInstance()); assertEquals(PeriodType.standard(), test.get

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>PeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_long_long_PeriodType_Chronology2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Period test = new Period(dt1.getMillis(), dt2.getMillis(), (PeriodType) null, null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_RI_RI1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Period test = new Period(dt1, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RI_RI2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1); Period test = new Period(dt1, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(1, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RI_RI3() throws Throwable { DateTime dt1 = null;

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> // 2002-06-09T01:00+01:00 DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1); Period test = new Period(dt1, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(3, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(1, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(0, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RI_RI4() throws Throwable { DateTime dt1 = new DateTime(2005, 7, 17, 1, 1, 1, 1); DateTime dt2 = null; // 2002-06-09T01:00+01:00 Period test = new Period(dt1, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(-3, test.getYears()); assertEquals(-1, test.getMonths()); assertEquals(-1, test.getWeeks()); assertEquals(-1, test.getDays()); assertEquals(0, test.getHours()); assertEquals(-1, test.getMinutes()); assertEquals(-1, test.getSeconds()); assertEquals(-1, test.getMillis()); } public void testConstructor_RI_RI5() throws Throwable { DateTime dt1 = null; // 2002-06-09T01:00+01:00 DateTime dt2 = null; // 2002-06-09T01:00+01:00 Period test = new Period(dt1, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_RI_RI_PeriodType1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Period test = new Period(dt1, dt2, null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1,

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RI_RI_PeriodType2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2004, 7, 10, 1, 1, 1, 1); Period test = new Period(dt1, dt2, PeriodType.dayTime()); assertEquals(PeriodType.dayTime(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(31, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RI_RI_PeriodType3() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2004, 6, 9, 1, 1, 1, 1); Period test = new Period(dt1, dt2, PeriodType.standard().withMillisRemoved()); assertEquals(PeriodType.standard().withMillisRemoved(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_RI_RI_PeriodType4() throws Throwable { DateTime dt1 = null; // 2002-06-09T01:00+01:00 DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1); Period test = new Period(dt1, dt2, PeriodType.standard()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(3, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(1, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(0, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RI_RI_PeriodType5() throws Throwable { DateTime dt1 = null; // 2002-06-09T01:00+01:00

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> DateTime dt2 = null; // 2002-06-09T01:00+01:00 Period test = new Period(dt1, dt2, PeriodType.standard()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_RP_RP1() throws Throwable { YearMonthDay dt1 = new YearMonthDay(2004, 6, 9); YearMonthDay dt2 = new YearMonthDay(2005, 7, 10); Period test = new Period(dt1, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_RP_RP2() throws Throwable { YearMonthDay dt1 = new YearMonthDay(2004, 6, 9); YearMonthDay dt2 = new YearMonthDay(2005, 5, 17); Period test = new Period(dt1, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(11, test.getMonths()); assertEquals(1, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_RP_RP2Local() throws Throwable { LocalDate dt1 = new LocalDate(2004, 6, 9); LocalDate dt2 = new LocalDate(2005, 5, 17); Period test = new Period(dt1, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(11, test.getMonths()); assertEquals(1, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_RP_RP3() throws Throwable { YearMonthDay dt1 = null; YearMonthDay dt2 = new YearMonthDay

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>(2005, 7, 17); try { new Period(dt1, dt2); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP4() throws Throwable { YearMonthDay dt1 = new YearMonthDay(2005, 7, 17); YearMonthDay dt2 = null; try { new Period(dt1, dt2); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP5() throws Throwable { YearMonthDay dt1 = null; YearMonthDay dt2 = null; try { new Period(dt1, dt2); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP6() throws Throwable { YearMonthDay dt1 = new YearMonthDay(2005, 7, 17); TimeOfDay dt2 = new TimeOfDay(10, 20, 30, 40); try { new Period(dt1, dt2); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP7() throws Throwable { Partial dt1 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.monthOfYear(), 12); Partial dt2 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 14); try { new Period(dt1, dt2); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP8() throws Throwable { Partial dt1 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 12); Partial dt2 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 14); try { new Period(dt1, dt2); fail(); } catch (IllegalArgumentException ex) {} } //----------------------------------------------------------------------- public void testConstructor_RP_RP_PeriodType1() throws Throwable { YearMonthDay dt1 = new YearMonthDay(2004, 6, 9); YearMonthDay dt2 = new YearMonthDay(2005, 7, 10); Period test = new Period(dt1, dt2, PeriodType.standard()); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_RP_RP_PeriodType2() throws Throwable { YearMonthDay dt1 = new YearMonthDay(2004, 6

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>, 9); YearMonthDay dt2 = new YearMonthDay(2005, 5, 17); Period test = new Period(dt1, dt2, PeriodType.yearMonthDay()); assertEquals(PeriodType.yearMonthDay(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(11, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(8, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_RP_RP_PeriodType2Local() throws Throwable { LocalDate dt1 = new LocalDate(2004, 6, 9); LocalDate dt2 = new LocalDate(2005, 5, 17); Period test = new Period(dt1, dt2, PeriodType.yearMonthDay()); assertEquals(PeriodType.yearMonthDay(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(11, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(8, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_RP_RP_PeriodType3() throws Throwable { YearMonthDay dt1 = null; YearMonthDay dt2 = new YearMonthDay(2005, 7, 17); try { new Period(dt1, dt2, PeriodType.standard()); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP_PeriodType4() throws Throwable { YearMonthDay dt1 = new YearMonthDay(2005, 7, 17); YearMonthDay dt2 = null; try { new Period(dt1, dt2); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP_PeriodType5() throws Throwable { YearMonthDay dt1 = null; YearMonthDay dt2 = null; try { new Period(dt1, dt2, PeriodType.standard()); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP_PeriodType6() throws Throwable { YearMonthDay dt1 = new YearMonthDay(2005, 7, 17); TimeOfDay dt2 = new TimeOfDay(10, 20, 30, 40); try { new Period(dt1, dt2, PeriodType.standard()); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP_PeriodType7() throws Throwable { Partial dt1 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.monthOfYear

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>(), 12); Partial dt2 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 14); try { new Period(dt1, dt2, PeriodType.standard()); fail(); } catch (IllegalArgumentException ex) {} } public void testConstructor_RP_RP_PeriodType8() throws Throwable { Partial dt1 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 12); Partial dt2 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 14); try { new Period(dt1, dt2, PeriodType.standard()); fail(); } catch (IllegalArgumentException ex) {} } //----------------------------------------------------------------------- public void testConstructor_RI_RD1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Duration dur = new Interval(dt1, dt2).toDuration(); Period test = new Period(dt1, dur); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RI_RD2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); Duration dur = null; Period test = new Period(dt1, dur); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_RI_RD_PeriodType1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Duration dur = new Interval(dt1, dt2).toDuration(); Period test = new Period(dt1, dur, PeriodType.yearDayTime()); assertEquals(PeriodType.yearDayTime(), test.getPeriodType()); assertEquals(1, test.get

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>Years()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(31, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RI_RD_PeriodType2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); Duration dur = null; Period test = new Period(dt1, dur, (PeriodType) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_RD_RI1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Duration dur = new Interval(dt1, dt2).toDuration(); Period test = new Period(dur, dt2); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RD_RI2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); Duration dur = null; Period test = new Period(dur, dt1); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- public void testConstructor_RD_RI_PeriodType1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>); Duration dur = new Interval(dt1, dt2).toDuration(); Period test = new Period(dur, dt2, PeriodType.yearDayTime()); assertEquals(PeriodType.yearDayTime(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(31, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } public void testConstructor_RD_RI_PeriodType2() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); Duration dur = null; Period test = new Period(dur, dt1, (PeriodType) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } //----------------------------------------------------------------------- /** * Test constructor (Object) */ public void testConstructor_Object1() throws Throwable { Period test = new Period("P1Y2M3D"); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(2, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(3, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_Object2() throws Throwable { Period test = new Period((Object) null); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_Object3() throws Throwable { Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4, PeriodType.dayTime())); assertEquals(PeriodType.dayTime(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(1, test.getHours()); assertEquals(2, test.getMinutes()); assertEquals(

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>3, test.getSeconds()); assertEquals(4, test.getMillis()); } public void testConstructor_Object4() throws Throwable { Period base = new Period(1, 1, 0, 1, 1, 1, 1, 1, PeriodType.standard()); Period test = new Period(base); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(1, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(1, test.getDays()); assertEquals(1, test.getHours()); assertEquals(1, test.getMinutes()); assertEquals(1, test.getSeconds()); assertEquals(1, test.getMillis()); } //----------------------------------------------------------------------- /** * Test constructor (Object) */ public void testConstructor_Object_PeriodType1() throws Throwable { Period test = new Period("P1Y2M3D", PeriodType.yearMonthDayTime()); assertEquals(PeriodType.yearMonthDayTime(), test.getPeriodType()); assertEquals(1, test.getYears()); assertEquals(2, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(3, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_Object_PeriodType2() throws Throwable { Period test = new Period((Object) null, PeriodType.yearMonthDayTime()); assertEquals(PeriodType.yearMonthDayTime(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testConstructor_Object_PeriodType3() throws Throwable { Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4, PeriodType.dayTime()), PeriodType.yearMonthDayTime()); assertEquals(PeriodType.yearMonthDayTime(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(1, test.getHours()); assertEquals(2, test.getMinutes()); assertEquals(3, test.getSeconds()); assertEquals(4, test.getMillis()); } public void testConstructor_Object_PeriodType4() throws Throwable { Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4, PeriodType.dayTime()), (PeriodType) null); assertEquals(PeriodType.dayTime(), test.get

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>PeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(1, test.getHours()); assertEquals(2, test.getMinutes()); assertEquals(3, test.getSeconds()); assertEquals(4, test.getMillis()); } //----------------------------------------------------------------------- public void testFactoryYears() throws Throwable { Period test = Period.years(6); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(6, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testFactoryMonths() throws Throwable { Period test = Period.months(6); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(6, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testFactoryWeeks() throws Throwable { Period test = Period.weeks(6); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(6, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testFactoryDays() throws Throwable { Period test = Period.days(6); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(6, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testFactoryHours() throws Throwable { Period test = Period.hours(6); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(6, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testFactoryMinutes() throws Throwable { Period test = Period.minutes(

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>6); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(6, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testFactorySeconds() throws Throwable { Period test = Period.seconds(6); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(6, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testFactoryMillis() throws Throwable { Period test = Period.millis(6); assertEquals(PeriodType.standard(), test.getPeriodType()); assertEquals(0, test.getYears()); assertEquals(0, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(0, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(6, test.getMillis()); } //----------------------------------------------------------------------- public void testFactoryFieldDifference1() throws Throwable { YearMonthDay start = new YearMonthDay(2005, 4, 9); DateTimeFieldType[] types = new DateTimeFieldType[] { DateTimeFieldType.year(), DateTimeFieldType.monthOfYear(), DateTimeFieldType.dayOfMonth(), }; Partial end = new Partial(types, new int[] {2004, 6, 7}); Period test = Period.fieldDifference(start, end); assertEquals(PeriodType.yearMonthDay(), test.getPeriodType()); assertEquals(-1, test.getYears()); assertEquals(2, test.getMonths()); assertEquals(0, test.getWeeks()); assertEquals(-2, test.getDays()); assertEquals(0, test.getHours()); assertEquals(0, test.getMinutes()); assertEquals(0, test.getSeconds()); assertEquals(0, test.getMillis()); } public void testFactoryFieldDifference2() throws Throwable { YearMonthDay ymd = new YearMonthDay(2005, 4, 9); try { Period.fieldDifference(ymd, (ReadablePartial) null); fail(); } catch (IllegalArgumentException ex) {} try { Period.fieldDifference((ReadablePartial) null, ymd); fail(); } catch (IllegalArgumentException ex) {} } public void testFactoryFieldDifference3() throws Throwable { YearMonthDay start = new YearMonthDay(2005, 4, 9); TimeOfDay endTime = new TimeOfDay(12, 30, 40, 0); try

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond); /** * Returns a datetime millisecond instant, from from the given instant, * hour, minute, second, and millisecond values. The set of given values * must refer to a valid datetime, or else an IllegalArgumentException is * thrown. * <p> * The default implementation calls upon separate DateTimeFields to * determine the result. Subclasses are encouraged to provide a more * efficient implementation. * * @param instant instant to start from * @param hourOfDay hour to use * @param minuteOfHour minute to use * @param secondOfMinute second to use * @param millisOfSecond millisecond to use * @return millisecond instant from 1970-01-01T00:00:00Z * @throws IllegalArgumentException if the values are invalid */ public abstract long getDateTimeMillis(long instant, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond); //----------------------------------------------------------------------- /** * Validates whether the values are valid for the fields of a partial instant. * * @param partial the partial instant to validate * @param values the values to validate, not null, match fields in partial * @throws IllegalArgumentException if the instant is invalid */ public abstract void validate(ReadablePartial partial, int[] values); /** * Gets the values of a partial from an instant. * * @param partial the partial instant to use * @param instant the instant to query * @return the values of this partial extracted from the instant */ public abstract int[] get(ReadablePartial partial, long instant); /** * Sets the partial into the instant. * * @param partial the partial instant to use * @param instant the instant to update * @return the updated instant */ public abstract long set(ReadablePartial partial, long instant); //----------------------------------------------------------------------- /** * Gets the values of a period from an interval. * * @param period the period instant to use * @param startInstant the start instant of an interval to query * @param endInstant the start instant of an interval to query * @return the values of the period extracted from the interval */ public abstract int[] get(ReadablePeriod period, long startInstant, long endInstant); /** * Gets the values of a period from an interval. * * @param period the period instant to use * @param duration the duration to query * @return the values of the period extracted from the duration */ public abstract int[] get(ReadablePeriod period, long duration); /** * Adds the period to the instant, specifying the number of times to add. * * @param period the period to add, null means add nothing * @param instant the instant to add to * @param scalar the number of times to add * @return the updated instant */ public abstract long add(ReadablePeriod period, long instant, int scalar); //----------------------------------------------------------------------- /** * Adds the

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2005 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time.chrono; import org.joda.time.DateTimeField; import org.joda.time.DateTimeFieldType; import org.joda.time.ReadablePartial; import org.joda.time.field.DecoratedDateTimeField; import org.joda.time.field.FieldUtils; /** * Provides time calculations for the year of era component of time. * * @author Brian S O'Neill * @since 1.0 */ final class GJYearOfEraDateTimeField extends DecoratedDateTimeField { private static final long serialVersionUID = -5961050944769862059L; private final BasicChronology iChronology; /** * Restricted constructor. */ GJYearOfEraDateTimeField(DateTimeField yearField, BasicChronology chronology) { super(yearField, DateTimeFieldType.yearOfEra()); iChronology = chronology; } public int get(long instant) { int year = getWrappedField().get(instant); if (year <= 0) { year = 1 - year; } return year; } public long add(long instant, int years) { return getWrappedField().add(instant, years); } public long add(long instant, long years) { return getWrappedField().add(instant, years); } public long addWrapField(long instant, int years) { return getWrappedField().addWrapField(instant, years); } public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int years) { return getWrappedField().addWrapField(instant, fieldIndex, values, years); } public int getDifference(long minuendInstant, long subtrahendInstant) { return getWrappedField().getDifference(minuendInstant, subtrahendInstant); } public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) { return getWrappedField().getDifferenceAsLong(minuendInstant, subtrahendInstant); } /** * Set the year component of the specified time instant. * * @param instant the time instant in millis to update. * @param year the year (0,29

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>0-04-20<br> * 2000-08-20 add minus nine months is 2000-11-20<br> * 2001-01-31 add one month is 2001-02-28<br> * 2001-01-31 add two months is 2001-03-31<br> * * @param instant the partial instant * @param fieldIndex the index of this field in the partial * @param values the values of the partial instant which should be updated * @param valueToAdd the value to add, in the units of the field * @return the passed in values * @throws IllegalArgumentException if the value is invalid or the maximum instant is reached */ public int[] add(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { if (valueToAdd == 0) { return values; } // there are more efficient algorithms than this (especially for time only fields) // trouble is when dealing with days and months, so we use this technique of // adding/removing one from the larger field at a time DateTimeField nextField = null; while (valueToAdd > 0) { int max = getMaximumValue(instant, values); long proposed = values[fieldIndex] + valueToAdd; if (proposed <= max) { values[fieldIndex] = (int) proposed; break; } if (nextField == null) { if (fieldIndex == 0) { throw new IllegalArgumentException("Maximum value exceeded for add"); } nextField = instant.getField(fieldIndex - 1); // test only works if this field is UTC (ie. local) if (getRangeDurationField().getType() != nextField.getDurationField().getType()) { throw new IllegalArgumentException("Fields invalid for add"); } } valueToAdd -= (max + 1) - values[fieldIndex]; // reduce the amount to add values = nextField.add(instant, fieldIndex - 1, values, 1); // add 1 to next bigger field values[fieldIndex] = getMinimumValue(instant, values); // reset this field to zero } while (valueToAdd < 0) { int min = getMinimumValue(instant, values); long proposed = values[fieldIndex] + valueToAdd; if (proposed >= min) { values[fieldIndex] = (int) proposed; break; } if (nextField == null) { if (fieldIndex == 0) { throw new IllegalArgumentException("Maximum value exceeded for add"); } nextField = instant.getField(fieldIndex - 1); if (getRangeDurationField().getType() != nextField.getDurationField().getType()) { throw new IllegalArgumentException("Fields invalid for add"); } } valueToAdd -= (min - 1) - values[fieldIndex]; // reduce the amount to add values

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> = nextField.add(instant, fieldIndex - 1, values, -1); // subtract 1 from next bigger field values[fieldIndex] = getMaximumValue(instant, values); // reset this field to max value } return set(instant, fieldIndex, values, values[fieldIndex]); // adjusts smaller fields } /** * Adds a value (which may be negative) to the partial instant, * wrapping the whole partial if the maximum size of the partial is reached. * <p> * The value will be added to this field, overflowing into larger fields * if necessary. Smaller fields should be unaffected, except where the * result would be an invalid value for a smaller field. In this case the * smaller field is adjusted to be in range. * <p> * Partial instants only contain some fields. This may result in a maximum * possible value, such as TimeOfDay normally being limited to 23:59:59:999. * If ths limit is reached by the addition, this method will wrap back to * 00:00:00.000. In fact, you would generally only use this method for * classes that have a limitation such as this. * <p> * For example, in the ISO chronology:<br> * 10:20:30 add 20 minutes is 10:40:30<br> * 10:20:30 add 45 minutes is 11:05:30<br> * 10:20:30 add 16 hours is 02:20:30<br> * * @param instant the partial instant * @param fieldIndex the index of this field in the partial * @param values the values of the partial instant which should be updated * @param valueToAdd the value to add, in the units of the field * @return the passed in values * @throws IllegalArgumentException if the value is invalid or the maximum instant is reached */ public int[] addWrapPartial(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { if (valueToAdd == 0) { return values; } // there are more efficient algorithms than this (especially for time only fields) // trouble is when dealing with days and months, so we use this technique of // adding/removing one from the larger field at a time DateTimeField nextField = null; while (valueToAdd > 0) { int max = getMaximumValue(instant, values); long proposed = values[fieldIndex] + valueToAdd; if (proposed <= max) { values[fieldIndex] = (int) proposed; break; } if (nextField == null) { if (fieldIndex == 0) { valueToAdd -= (max + 1) - values[fieldIndex]; values[fieldIndex] = getMinimumValue(instant, values); continue; } nextField

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> = instant.getField(fieldIndex - 1); // test only works if this field is UTC (ie. local) if (getRangeDurationField().getType() != nextField.getDurationField().getType()) { throw new IllegalArgumentException("Fields invalid for add"); } } valueToAdd -= (max + 1) - values[fieldIndex]; // reduce the amount to add values = nextField.addWrapPartial(instant, fieldIndex - 1, values, 1); // add 1 to next bigger field values[fieldIndex] = getMinimumValue(instant, values); // reset this field to zero } while (valueToAdd < 0) { int min = getMinimumValue(instant, values); long proposed = values[fieldIndex] + valueToAdd; if (proposed >= min) { values[fieldIndex] = (int) proposed; break; } if (nextField == null) { if (fieldIndex == 0) { valueToAdd -= (min - 1) - values[fieldIndex]; values[fieldIndex] = getMaximumValue(instant, values); continue; } nextField = instant.getField(fieldIndex - 1); if (getRangeDurationField().getType() != nextField.getDurationField().getType()) { throw new IllegalArgumentException("Fields invalid for add"); } } valueToAdd -= (min - 1) - values[fieldIndex]; // reduce the amount to add values = nextField.addWrapPartial(instant, fieldIndex - 1, values, -1); // subtract 1 from next bigger field values[fieldIndex] = getMaximumValue(instant, values); // reset this field to max value } return set(instant, fieldIndex, values, values[fieldIndex]); // adjusts smaller fields } /** * Adds a value (which may be negative) to the instant value, * wrapping within this field. * <p> * The value will be added to this field. If the value is too large to be * added solely to this field then it wraps. Larger fields are always * unaffected. Smaller fields should be unaffected, except where the * result would be an invalid value for a smaller field. In this case the * smaller field is adjusted to be in range. * <p> * For example, in the ISO chronology:<br> * 2000-08-20 addWrapField six months is 2000-02-20<br> * 2000-08-20 addWrapField twenty months is 2000-04-20<br> * 2000-08-20 addWrapField minus nine months is 2000-11-20<br> * 2001-01-31 addWrapField one month is 2001-02-28<br> * 2001-01-31 add

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>WrapField two months is 2001-03-31<br> * <p> * The default implementation internally calls set. Subclasses are * encouraged to provide a more efficient implementation. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to add to * @param value the value to add, in the units of the field * @return the updated milliseconds */ public long addWrapField(long instant, int value) { int current = get(instant); int wrapped = FieldUtils.getWrappedValue (current, value, getMinimumValue(instant), getMaximumValue(instant)); return set(instant, wrapped); } /** * Adds a value (which may be negative) to the partial instant, * wrapping within this field. * <p> * The value will be added to this field. If the value is too large to be * added solely to this field then it wraps. Larger fields are always * unaffected. Smaller fields should be unaffected, except where the * result would be an invalid value for a smaller field. In this case the * smaller field is adjusted to be in range. * <p> * For example, in the ISO chronology:<br> * 2000-08-20 addWrapField six months is 2000-02-20<br> * 2000-08-20 addWrapField twenty months is 2000-04-20<br> * 2000-08-20 addWrapField minus nine months is 2000-11-20<br> * 2001-01-31 addWrapField one month is 2001-02-28<br> * 2001-01-31 addWrapField two months is 2001-03-31<br> * <p> * The default implementation internally calls set. Subclasses are * encouraged to provide a more efficient implementation. * * @param instant the partial instant * @param fieldIndex the index of this field in the instant * @param values the values of the partial instant which should be updated * @param valueToAdd the value to add, in the units of the field * @return the passed in values * @throws IllegalArgumentException if the value is invalid */ public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { int current = values[fieldIndex]; int wrapped = FieldUtils.getWrappedValue (current, valueToAdd, getMinimumValue(instant), getMaximumValue(instant)); return set(instant, fieldIndex, values, wrapped); // adjusts smaller fields } //----------------------------------------------------------------------- /** * Computes the difference between two instants, as measured in the units * of this field. Any fractional units

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> the specified partial instant. * <p> * The value of this field (specified by the index) will be set. * If the value is invalid, an exception if thrown. * <p> * If setting this field would make other fields invalid, then those fields * may be changed. For example if the current date is the 31st January, and * the month is set to February, the day would be invalid. Instead, the day * would be changed to the closest value - the 28th/29th February as appropriate. * * @param partial the partial instant * @param fieldIndex the index of this field in the instant * @param values the values to update * @param newValue the value to set, in the units of the field * @return the updated values * @throws IllegalArgumentException if the value is invalid */ public int[] set(ReadablePartial partial, int fieldIndex, int[] values, int newValue) { FieldUtils.verifyValueBounds(this, newValue, getMinimumValue(partial, values), getMaximumValue(partial, values)); values[fieldIndex] = newValue; // may need to adjust smaller fields for (int i = fieldIndex + 1; i < partial.size(); i++) { DateTimeField field = partial.getField(i); if (values[i] > field.getMaximumValue(partial, values)) { values[i] = field.getMaximumValue(partial, values); } if (values[i] < field.getMinimumValue(partial, values)) { values[i] = field.getMinimumValue(partial, values); } } return values; } /** * Sets a value in the milliseconds supplied from a human-readable, text value. * If the specified locale is null, the default locale is used. * <p> * This implementation uses <code>convertText(String, Locale)</code> and * {@link #set(long, int)}. * <p> * Note: subclasses that override this method should also override * getAsText. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to set in * @param text the text value to set * @param locale the locale to use for selecting a text symbol, null for default * @return the updated milliseconds * @throws IllegalArgumentException if the text value is invalid */ public long set(long instant, String text, Locale locale) { int value = convertText(text, locale); return set(instant, value); } /** * Sets a value in the milliseconds supplied from a human-readable, text value. * <p> * This implementation uses {@link #set(long, String, Locale)}. * <p> * Note: subclasses that override this method should also override getAsText. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to set in * @

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>param text the text value to set * @return the updated milliseconds * @throws IllegalArgumentException if the text value is invalid */ public final long set(long instant, String text) { return set(instant, text, null); } /** * Sets a value in the milliseconds supplied from a human-readable, text value. * If the specified locale is null, the default locale is used. * <p> * This implementation uses <code>convertText(String, Locale)</code> and * {@link #set(ReadablePartial, int, int[], int)}. * * @param instant the partial instant * @param fieldIndex the index of this field in the instant * @param values the values of the partial instant which should be updated * @param text the text value to set * @param locale the locale to use for selecting a text symbol, null for default * @return the passed in values * @throws IllegalArgumentException if the text value is invalid */ public int[] set(ReadablePartial instant, int fieldIndex, int[] values, String text, Locale locale) { int value = convertText(text, locale); return set(instant, fieldIndex, values, value); } /** * Convert the specified text and locale into a value. * * @param text the text to convert * @param locale the locale to convert using * @return the value extracted from the text * @throws IllegalArgumentException if the text is invalid */ protected int convertText(String text, Locale locale) { try { return Integer.parseInt(text); } catch (NumberFormatException ex) { throw new IllegalFieldValueException(getType(), text); } } // Extra information API //------------------------------------------------------------------------ /** * Returns the duration per unit value of this field. For example, if this * field represents "hour of day", then the unit duration is an hour. * * @return the duration of this field, or UnsupportedDurationField if field * has no duration */ public abstract DurationField getDurationField(); /** * Returns the range duration of this field. For example, if this field * represents "hour of day", then the range duration is a day. * * @return the range duration of this field, or null if field has no range */ public abstract DurationField getRangeDurationField(); /** * Returns whether this field is 'leap' for the specified instant. * <p> * For example, a leap year would return true, a non leap year would return * false. * <p> * This implementation returns false. * * @return true if the field is 'leap' */ public boolean isLeap(long instant) { return false; } /** * Gets the amount by which this field is 'leap' for the specified instant. * <p> * For example, a leap year would return one, a non leap year would return * zero. * <p> * This implementation returns zero. */ public int getLeapAmount(long

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> instant) { return 0; } /** * If this field were to leap, then it would be in units described by the * returned duration. If this field doesn't ever leap, null is returned. * <p> * This implementation returns null. */ public DurationField getLeapDurationField() { return null; } /** * Get the minimum allowable value for this field. * * @return the minimum valid value for this field, in the units of the * field */ public abstract int getMinimumValue(); /** * Get the minimum value for this field evaluated at the specified time. * <p> * This implementation returns the same as {@link #getMinimumValue()}. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to query * @return the minimum value for this field, in the units of the field */ public int getMinimumValue(long instant) { return getMinimumValue(); } /** * Get the minimum value for this field evaluated at the specified instant. * <p> * This implementation returns the same as {@link #getMinimumValue()}. * * @param instant the partial instant to query * @return the minimum value for this field, in the units of the field */ public int getMinimumValue(ReadablePartial instant) { return getMinimumValue(); } /** * Get the minimum value for this field using the partial instant and * the specified values. * <p> * This implementation returns the same as {@link #getMinimumValue(ReadablePartial)}. * * @param instant the partial instant to query * @param values the values to use * @return the minimum value for this field, in the units of the field */ public int getMinimumValue(ReadablePartial instant, int[] values) { return getMinimumValue(instant); } /** * Get the maximum allowable value for this field. * * @return the maximum valid value for this field, in the units of the * field */ public abstract int getMaximumValue(); /** * Get the maximum value for this field evaluated at the specified time. * <p> * This implementation returns the same as {@link #getMaximumValue()}. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to query * @return the maximum value for this field, in the units of the field */ public int getMaximumValue(long instant) { return getMaximumValue(); } /** * Get the maximum value for this field evaluated at the specified instant. * <p> * This implementation returns the same as {@link #getMaximumValue()}. * * @param instant the partial instant to query * @return the maximum value for this field, in the units of the field */ public int getMaximumValue(ReadablePartial instant) { return getMaximumValue(); } /** * Get the maximum

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> value for this field using the partial instant and * the specified values. * <p> * This implementation returns the same as {@link #getMaximumValue(ReadablePartial)}. * * @param instant the partial instant to query * @param values the values to use * @return the maximum value for this field, in the units of the field */ public int getMaximumValue(ReadablePartial instant, int[] values) { return getMaximumValue(instant); } /** * Get the maximum text value for this field. The default implementation * returns the equivalent of Integer.toString(getMaximumValue()).length(). * * @param locale the locale to use for selecting a text symbol * @return the maximum text length */ public int getMaximumTextLength(Locale locale) { int max = getMaximumValue(); if (max >= 0) { if (max < 10) { return 1; } else if (max < 100) { return 2; } else if (max < 1000) { return 3; } } return Integer.toString(max).length(); } /** * Get the maximum short text value for this field. The default * implementation returns getMaximumTextLength(). * * @param locale the locale to use for selecting a text symbol * @return the maximum short text length */ public int getMaximumShortTextLength(Locale locale) { return getMaximumTextLength(locale); } // Calculation API //------------------------------------------------------------------------ /** * Round to the lowest whole unit of this field. After rounding, the value * of this field and all fields of a higher magnitude are retained. The * fractional millis that cannot be expressed in whole increments of this * field are set to minimum. * <p> * For example, a datetime of 2002-11-02T23:34:56.789, rounded to the * lowest whole hour is 2002-11-02T23:00:00.000. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to round * @return rounded milliseconds */ public abstract long roundFloor(long instant); /** * Round to the highest whole unit of this field. The value of this field * and all fields of a higher magnitude may be incremented in order to * achieve this result. The fractional millis that cannot be expressed in * whole increments of this field are set to minimum. * <p> * For example, a datetime of 2002-11-02T23:34:56.789, rounded to the * highest whole hour is 2002-11-03T00:00:00.000. * <p> * The default implementation calls roundFloor, and if the instant is * modified as

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> used. * <p> * NOTE: If the {@code java.util.TimeZone} default is updated <i>after</i> calling this * method, then the change will not be picked up here. * * @return the default datetime zone object */ public static DateTimeZone getDefault() { DateTimeZone zone = cDefault; if (zone == null) { synchronized(DateTimeZone.class) { zone = cDefault; if (zone == null) { DateTimeZone temp = null; try { try { String id = System.getProperty("user.timezone"); if (id != null) { // null check avoids stack overflow temp = forID(id); } } catch (RuntimeException ex) { // ignored } if (temp == null) { temp = forTimeZone(TimeZone.getDefault()); } } catch (IllegalArgumentException ex) { // ignored } if (temp == null) { temp = UTC; } cDefault = zone = temp; } } } return zone; } /** * Sets the default time zone. * <p> * NOTE: Calling this method does <i>not</i> set the {@code java.util.TimeZone} default. * * @param zone the default datetime zone object, must not be null * @throws IllegalArgumentException if the zone is null * @throws SecurityException if the application has insufficient security rights */ public static void setDefault(DateTimeZone zone) throws SecurityException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new JodaTimePermission("DateTimeZone.setDefault")); } if (zone == null) { throw new IllegalArgumentException("The datetime zone must not be null"); } synchronized(DateTimeZone.class) { cDefault = zone; } } //----------------------------------------------------------------------- /** * Gets a time zone instance for the specified time zone id. * <p> * The time zone id may be one of those returned by getAvailableIDs. * Short ids, as accepted by {@link java.util.TimeZone}, are not accepted. * All IDs must be specified in the long format. * The exception is UTC, which is an acceptable id. * <p> * Alternatively a locale independent, fixed offset, datetime zone can * be specified. The form <code>[+-]hh:mm</code> can be used. * * @param id the ID of the datetime zone, null means default * @return the DateTimeZone object for the ID * @throws IllegalArgumentException if the ID is not recognised */ @FromString public static DateTimeZone forID(String id) { if (id == null) { return getDefault(); } if (id.equals("UTC")) { return DateTimeZone.UTC; } DateTimeZone zone = cProvider.getZone(id); if (zone != null) { return zone; } if (id.startsWith("+") || id.startsWith("-")) { int offset = parseOffset(id); if

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> DateTimeZone. * * @return the provider */ public static Provider getProvider() { return cProvider; } /** * Sets the zone provider factory. * <p> * The zone provider is a pluggable instance factory that supplies the * actual instances of DateTimeZone. * * @param provider provider to use, or null for default * @throws SecurityException if you do not have the permission DateTimeZone.setProvider * @throws IllegalArgumentException if the provider is invalid */ public static void setProvider(Provider provider) throws SecurityException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new JodaTimePermission("DateTimeZone.setProvider")); } setProvider0(provider); } /** * Sets the zone provider factory without performing the security check. * * @param provider provider to use, or null for default * @throws IllegalArgumentException if the provider is invalid */ private static void setProvider0(Provider provider) { if (provider == null) { provider = getDefaultProvider(); } Set<String> ids = provider.getAvailableIDs(); if (ids == null || ids.size() == 0) { throw new IllegalArgumentException ("The provider doesn't have any available ids"); } if (!ids.contains("UTC")) { throw new IllegalArgumentException("The provider doesn't support UTC"); } if (!UTC.equals(provider.getZone("UTC"))) { throw new IllegalArgumentException("Invalid UTC zone provided"); } cProvider = provider; cAvailableIDs = ids; } /** * Gets the default zone provider. * <p> * Tries the system property <code>org.joda.time.DateTimeZone.Provider</code>. * Then tries a <code>ZoneInfoProvider</code> using the data in <code>org/joda/time/tz/data</code>. * Then uses <code>UTCProvider</code>. * * @return the default name provider */ private static Provider getDefaultProvider() { Provider provider = null; try { String providerClass = System.getProperty("org.joda.time.DateTimeZone.Provider"); if (providerClass != null) { try { provider = (Provider) Class.forName(providerClass).newInstance(); } catch (Exception ex) { Thread thread = Thread.currentThread(); thread.getThreadGroup().uncaughtException(thread, ex); } } } catch (SecurityException ex) { // ignored } if (provider == null) { try { provider = new ZoneInfoProvider("org/joda/time/tz/data"); } catch (Exception ex) { Thread thread = Thread.currentThread(); thread.getThreadGroup().uncaughtException(thread, ex); } } if (provider == null) { provider = new UTCProvider(); } return provider; } //----------------------------------------------------------------------- /** * Gets the name provider factory. * <p> * The name provider is a pluggable instance factory that supplies the

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * names of each DateTimeZone. * * @return the provider */ public static NameProvider getNameProvider() { return cNameProvider; } /** * Sets the name provider factory. * <p> * The name provider is a pluggable instance factory that supplies the * names of each DateTimeZone. * * @param nameProvider provider to use, or null for default * @throws SecurityException if you do not have the permission DateTimeZone.setNameProvider * @throws IllegalArgumentException if the provider is invalid */ public static void setNameProvider(NameProvider nameProvider) throws SecurityException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new JodaTimePermission("DateTimeZone.setNameProvider")); } setNameProvider0(nameProvider); } /** * Sets the name provider factory without performing the security check. * * @param nameProvider provider to use, or null for default * @throws IllegalArgumentException if the provider is invalid */ private static void setNameProvider0(NameProvider nameProvider) { if (nameProvider == null) { nameProvider = getDefaultNameProvider(); } cNameProvider = nameProvider; } /** * Gets the default name provider. * <p> * Tries the system property <code>org.joda.time.DateTimeZone.NameProvider</code>. * Then uses <code>DefaultNameProvider</code>. * * @return the default name provider */ private static NameProvider getDefaultNameProvider() { NameProvider nameProvider = null; try { String providerClass = System.getProperty("org.joda.time.DateTimeZone.NameProvider"); if (providerClass != null) { try { nameProvider = (NameProvider) Class.forName(providerClass).newInstance(); } catch (Exception ex) { Thread thread = Thread.currentThread(); thread.getThreadGroup().uncaughtException(thread, ex); } } } catch (SecurityException ex) { // ignore } if (nameProvider == null) { nameProvider = new DefaultNameProvider(); } return nameProvider; } //----------------------------------------------------------------------- /** * Converts an old style id to a new style id. * * @param id the old style id * @return the new style id, null if not found */ private static synchronized String getConvertedId(String id) { Map<String, String> map = cZoneIdConversion; if (map == null) { // Backwards compatibility with TimeZone. map = new HashMap<String, String>(); map.put("GMT", "UTC"); map.put("WET", "WET"); map.put("CET", "CET"); map.put("MET", "CET"); map.put("ECT", "CET"); map.put("EET", "EET"); map.put("MIT", "Pacific/Apia"); map.put("HST", "Pacific/Honolulu"); // JDK 1.1

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> period type. * @since 1.4 */ public static final Period ZERO = new Period(); /** Serialization version */ private static final long serialVersionUID = 741052353876488155L; //----------------------------------------------------------------------- /** * Parses a {@code Period} from the specified string. * <p> * This uses {@link ISOPeriodFormat#standard()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static Period parse(String str) { return parse(str, ISOPeriodFormat.standard()); } /** * Parses a {@code Period} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static Period parse(String str, PeriodFormatter formatter) { return formatter.parsePeriod(str); } //----------------------------------------------------------------------- /** * Create a period with a specified number of years. * <p> * The standard period type is used, thus you can add other fields such * as months or days using the <code>withXxx()</code> methods. * For example, <code>Period.years(2).withMonths(6);</code> * <p> * If you want a year-based period that cannot have other fields added, * then you should consider using {@link Years}. * * @param years the amount of years in this period * @return the period */ public static Period years(int years) { return new Period(new int[] {years, 0, 0, 0, 0, 0, 0, 0, 0}, PeriodType.standard()); } /** * Create a period with a specified number of months. * <p> * The standard period type is used, thus you can add other fields such * as years or days using the <code>withXxx()</code> methods. * For example, <code>Period.months(2).withDays(6);</code> * <p> * If you want a month-based period that cannot have other fields added, * then you should consider using {@link Months}. * * @param months the amount of months in this period * @return the period */ public static Period months(int months) { return new Period(new int[] {0, months, 0, 0, 0, 0, 0, 0}, PeriodType.standard()); } /** * Create a period with a specified number of weeks. * <p> * The standard period type is used, thus you can add other fields such * as months or days using the <code>withXxx()</code> methods. * For example, <code>Period.weeks(2).withDays(6);</code> * <p> * If you want a week-based period that cannot have other fields added

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>, * then you should consider using {@link Weeks}. * * @param weeks the amount of weeks in this period * @return the period */ public static Period weeks(int weeks) { return new Period(new int[] {0, 0, weeks, 0, 0, 0, 0, 0}, PeriodType.standard()); } /** * Create a period with a specified number of days. * <p> * The standard period type is used, thus you can add other fields such * as months or weeks using the <code>withXxx()</code> methods. * For example, <code>Period.days(2).withHours(6);</code> * <p> * If you want a day-based period that cannot have other fields added, * then you should consider using {@link Days}. * * @param days the amount of days in this period * @return the period */ public static Period days(int days) { return new Period(new int[] {0, 0, 0, days, 0, 0, 0, 0}, PeriodType.standard()); } /** * Create a period with a specified number of hours. * <p> * The standard period type is used, thus you can add other fields such * as months or days using the <code>withXxx()</code> methods. * For example, <code>Period.hours(2).withMinutes(30);</code> * <p> * If you want a hour-based period that cannot have other fields added, * then you should consider using {@link Hours}. * * @param hours the amount of hours in this period * @return the period */ public static Period hours(int hours) { return new Period(new int[] {0, 0, 0, 0, hours, 0, 0, 0}, PeriodType.standard()); } /** * Create a period with a specified number of minutes. * <p> * The standard period type is used, thus you can add other fields such * as days or hours using the <code>withXxx()</code> methods. * For example, <code>Period.minutes(2).withSeconds(30);</code> * <p> * If you want a minute-based period that cannot have other fields added, * then you should consider using {@link Minutes}. * * @param minutes the amount of minutes in this period * @return the period */ public static Period minutes(int minutes) { return new Period(new int[] {0, 0, 0, 0, 0, minutes, 0, 0}, PeriodType.standard()); } /** * Create a period with a specified number of seconds. * <p> * The standard period type is used, thus you can add other fields such * as days or hours using the <code>withXxx()</code> methods. * For example, <code>Period

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>.seconds(2).withMillis(30);</code> * <p> * If you want a second-based period that cannot have other fields added, * then you should consider using {@link Seconds}. * * @param seconds the amount of seconds in this period * @return the period */ public static Period seconds(int seconds) { return new Period(new int[] {0, 0, 0, 0, 0, 0, seconds, 0}, PeriodType.standard()); } /** * Create a period with a specified number of millis. * <p> * The standard period type is used, thus you can add other fields such * as days or hours using the <code>withXxx()</code> methods. * For example, <code>Period.millis(20).withSeconds(30);</code> * * @param millis the amount of millis in this period * @return the period */ public static Period millis(int millis) { return new Period(new int[] {0, 0, 0, 0, 0, 0, 0, millis}, PeriodType.standard()); } //----------------------------------------------------------------------- /** * Creates a period from two partially specified times, calculating * by field difference. * <p> * The two partials must contain the same fields, thus you can specify * two <code>LocalDate</code> objects, or two <code>LocalTime</code> objects, * but not one of each. Also, the partial may not contain overlapping * fields, such as dayOfWeek and dayOfMonth. * <p> * Calculation by field difference works by extracting the difference * one field at a time and not wrapping into other fields. * Thus 2005-06-09/2007-04-12 will yield P1Y-2M3D. * <p> * For example, you have an event that always runs from the 27th of * each month to the 2nd of the next month. If you calculate this * period using a standard constructor, then you will get between * P3D and P6D depending on the month. If you use this method, then * you will get P1M-25D. This field-difference based period can * be successfully applied to each month of the year to obtain the * correct end date for a given start date. * * @param start the start of the period, must not be null * @param end the end of the period, must not be null * @throws IllegalArgumentException if the partials are null or invalid * @since 1.1 */ public static Period fieldDifference(ReadablePartial start, ReadablePartial end) { if (start == null || end == null) { throw new IllegalArgumentException("ReadablePartial objects must not be null"); } if (start.size() != end.size()) { throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields"); } DurationFieldType[] types =

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> new DurationFieldType[start.size()]; int[] values = new int[start.size()]; for (int i = 0, isize = start.size(); i < isize; i++) { if (start.getFieldType(i) != end.getFieldType(i)) { throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields"); } types[i] = start.getFieldType(i).getDurationType(); if (i > 0 && types[i - 1] == types[i]) { throw new IllegalArgumentException("ReadablePartial objects must not have overlapping fields"); } values[i] = end.getValue(i) - start.getValue(i); } return new Period(values, PeriodType.forFields(types)); } //----------------------------------------------------------------------- /** * Creates a new empty period with the standard set of fields. * <p> * One way to initialise a period is as follows: * <pre> * Period = new Period().withYears(6).withMonths(3).withSeconds(23); * </pre> * Bear in mind that this creates four period instances in total, three of * which are immediately discarded. * The alterative is more efficient, but less readable: * <pre> * Period = new Period(6, 3, 0, 0, 0, 0, 23, 0); * </pre> * The following is also slightly less wasteful: * <pre> * Period = Period.years(6).withMonths(3).withSeconds(23); * </pre> */ public Period() { super(0L, null, null); } /** * Create a period from a set of field values using the standard set of fields. * Note that the parameters specify the time fields hours, minutes, * seconds and millis, not the date fields. * * @param hours amount of hours in this period * @param minutes amount of minutes in this period * @param seconds amount of seconds in this period * @param millis amount of milliseconds in this period */ public Period(int hours, int minutes, int seconds, int millis) { super(0, 0, 0, 0, hours, minutes, seconds, millis, PeriodType.standard()); } /** * Create a period from a set of field values using the standard set of fields. * * @param years amount of years in this period * @param months amount of months in this period * @param weeks amount of weeks in this period * @param days amount of days in this period * @param hours amount of hours in this period * @param minutes amount of minutes in this period * @param seconds amount of seconds in this period * @param millis amount of milliseconds in this period */ public Period(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis) { super(years, months, weeks, days, hours, minutes

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>, seconds, millis, PeriodType.standard()); } /** * Create a period from a set of field values. * <p> * There is usually little need to use this constructor. * The period type is used primarily to define how to split an interval into a period. * As this constructor already is split, the period type does no real work. * * @param years amount of years in this period, which must be zero if unsupported * @param months amount of months in this period, which must be zero if unsupported * @param weeks amount of weeks in this period, which must be zero if unsupported * @param days amount of days in this period, which must be zero if unsupported * @param hours amount of hours in this period, which must be zero if unsupported * @param minutes amount of minutes in this period, which must be zero if unsupported * @param seconds amount of seconds in this period, which must be zero if unsupported * @param millis amount of milliseconds in this period, which must be zero if unsupported * @param type which set of fields this period supports, null means AllType * @throws IllegalArgumentException if an unsupported field's value is non-zero */ public Period(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis, PeriodType type) { super(years, months, weeks, days, hours, minutes, seconds, millis, type); } /** * Creates a period from the given millisecond duration using the standard * set of fields. * <p> * Only precise fields in the period type will be used. * For the standard period type this is the time fields only. * Thus the year, month, week and day fields will not be populated. * <p> * If the duration is small, less than one day, then this method will perform * as you might expect and split the fields evenly. * <p> * If the duration is larger than one day then all the remaining duration will * be stored in the largest available precise field, hours in this case. * <p> * For example, a duration equal to (365 + 60 + 5) days will be converted to * ((365 + 60 + 5) * 24) hours by this constructor. * <p> * For more control over the conversion process, you have two options: * <ul> * <li>convert the duration to an {@link Interval}, and from there obtain the period * <li>specify a period type that contains precise definitions of the day and larger * fields, such as UTC * </ul> * * @param duration the duration, in milliseconds */ public Period(long duration) { super(duration); } /** * Creates a period from the given millisecond duration. * <p> * Only precise fields in the period type will be used. * Imprecise fields will not be populated. * <p> * If the duration is small then this method will

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> perform * as you might expect and split the fields evenly. * <p> * If the duration is large then all the remaining duration will * be stored in the largest available precise field. * For details as to which fields are precise, review the period type javadoc. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard */ public Period(long duration, PeriodType type) { super(duration, type, null); } /** * Creates a period from the given millisecond duration using the standard * set of fields. * <p> * Only precise fields in the period type will be used. * Imprecise fields will not be populated. * <p> * If the duration is small then this method will perform * as you might expect and split the fields evenly. * <p> * If the duration is large then all the remaining duration will * be stored in the largest available precise field. * For details as to which fields are precise, review the period type javadoc. * * @param duration the duration, in milliseconds * @param chronology the chronology to use to split the duration, null means ISO default */ public Period(long duration, Chronology chronology) { super(duration, null, chronology); } /** * Creates a period from the given millisecond duration. * <p> * Only precise fields in the period type will be used. * Imprecise fields will not be populated. * <p> * If the duration is small then this method will perform * as you might expect and split the fields evenly. * <p> * If the duration is large then all the remaining duration will * be stored in the largest available precise field. * For details as to which fields are precise, review the period type javadoc. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chronology the chronology to use to split the duration, null means ISO default */ public Period(long duration, PeriodType type, Chronology chronology) { super(duration, type, chronology); } /** * Creates a period from the given interval endpoints using the standard * set of fields. * * @param startInstant interval start, in milliseconds * @param endInstant interval end, in milliseconds */ public Period(long startInstant, long endInstant) { super(startInstant, endInstant, null, null); } /** * Creates a period from the given interval endpoints. * * @param startInstant interval start, in milliseconds * @param endInstant interval end, in milliseconds * @param type which set of fields this period supports, null means standard */ public Period(long startInstant, long endInstant, PeriodType type) { super(startInstant, endInstant, type, null); } /** * Creates a period

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> from the given interval endpoints using the standard * set of fields. * * @param startInstant interval start, in milliseconds * @param endInstant interval end, in milliseconds * @param chrono the chronology to use, null means ISO in default zone */ public Period(long startInstant, long endInstant, Chronology chrono) { super(startInstant, endInstant, null, chrono); } /** * Creates a period from the given interval endpoints. * * @param startInstant interval start, in milliseconds * @param endInstant interval end, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO in default zone */ public Period(long startInstant, long endInstant, PeriodType type, Chronology chrono) { super(startInstant, endInstant, type, chrono); } /** * Creates a period from the given interval endpoints using the standard * set of fields. * * @param startInstant interval start, null means now * @param endInstant interval end, null means now */ public Period(ReadableInstant startInstant, ReadableInstant endInstant) { super(startInstant, endInstant, null); } /** * Creates a period from the given interval endpoints. * * @param startInstant interval start, null means now * @param endInstant interval end, null means now * @param type which set of fields this period supports, null means standard */ public Period(ReadableInstant startInstant, ReadableInstant endInstant, PeriodType type) { super(startInstant, endInstant, type); } /** * Creates a period from two partially specified times. * <p> * The two partials must contain the same fields, thus you can specify * two <code>LocalDate</code> objects, or two <code>LocalTime</code> objects, * but not one of each. * As these are Partial objects, time zones have no effect on the result. * <p> * The two partials must also both be contiguous - see * {@link DateTimeUtils#isContiguous(ReadablePartial)} for a definition. * Both <code>LocalDate</code> and <code>LocalTime</code> are contiguous. * <p> * An alternative way of constructing a Period from two Partials * is {@link #fieldDifference(ReadablePartial, ReadablePartial)}. * That method handles all kinds of partials. * * @param start the start of the period, must not be null * @param end the end of the period, must not be null * @throws IllegalArgumentException if the partials are null or invalid * @since 1.1 */ public Period(ReadablePartial start, ReadablePartial end) { super(start, end, null); } /** * Creates a period from two partially specified times. * <p> * The two partials must contain the same fields, thus you can specify * two <code

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>>LocalDate</code> objects, or two <code>LocalTime</code> objects, * but not one of each. * As these are Partial objects, time zones have no effect on the result. * <p> * The two partials must also both be contiguous - see * {@link DateTimeUtils#isContiguous(ReadablePartial)} for a definition. * Both <code>LocalDate</code> and <code>LocalTime</code> are contiguous. * <p> * An alternative way of constructing a Period from two Partials * is {@link #fieldDifference(ReadablePartial, ReadablePartial)}. * That method handles all kinds of partials. * * @param start the start of the period, must not be null * @param end the end of the period, must not be null * @param type which set of fields this period supports, null means standard * @throws IllegalArgumentException if the partials are null or invalid * @since 1.1 */ public Period(ReadablePartial start, ReadablePartial end, PeriodType type) { super(start, end, type); } /** * Creates a period from the given start point and the duration. * * @param startInstant the interval start, null means now * @param duration the duration of the interval, null means zero-length */ public Period(ReadableInstant startInstant, ReadableDuration duration) { super(startInstant, duration, null); } /** * Creates a period from the given start point and the duration. * * @param startInstant the interval start, null means now * @param duration the duration of the interval, null means zero-length * @param type which set of fields this period supports, null means standard */ public Period(ReadableInstant startInstant, ReadableDuration duration, PeriodType type) { super(startInstant, duration, type); } /** * Creates a period from the given duration and end point. * * @param duration the duration of the interval, null means zero-length * @param endInstant the interval end, null means now */ public Period(ReadableDuration duration, ReadableInstant endInstant) { super(duration, endInstant, null); } /** * Creates a period from the given duration and end point. * * @param duration the duration of the interval, null means zero-length * @param endInstant the interval end, null means now * @param type which set of fields this period supports, null means standard */ public Period(ReadableDuration duration, ReadableInstant endInstant, PeriodType type) { super(duration, endInstant, type); } /** * Creates a period by converting or copying from another object. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadablePeriod, ReadableInterval and String. * The String formats are described by {@link ISOPeriodFormat#standard()}. * * @param period period

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> to convert * @throws IllegalArgumentException if period is invalid * @throws UnsupportedOperationException if an unsupported field's value is non-zero */ public Period(Object period) { super(period, null, null); } /** * Creates a period by converting or copying from another object. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadablePeriod, ReadableInterval and String. * The String formats are described by {@link ISOPeriodFormat#standard()}. * * @param period period to convert * @param type which set of fields this period supports, null means use converter * @throws IllegalArgumentException if period is invalid * @throws UnsupportedOperationException if an unsupported field's value is non-zero */ public Period(Object period, PeriodType type) { super(period, type, null); } /** * Creates a period by converting or copying from another object. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadablePeriod, ReadableInterval and String. * The String formats are described by {@link ISOPeriodFormat#standard()}. * * @param period period to convert * @param chrono the chronology to use, null means ISO in default zone * @throws IllegalArgumentException if period is invalid * @throws UnsupportedOperationException if an unsupported field's value is non-zero */ public Period(Object period, Chronology chrono) { super(period, null, chrono); } /** * Creates a period by converting or copying from another object. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadablePeriod, ReadableInterval and String. * The String formats are described by {@link ISOPeriodFormat#standard()}. * * @param period period to convert * @param type which set of fields this period supports, null means use converter * @param chrono the chronology to use, null means ISO in default zone * @throws IllegalArgumentException if period is invalid * @throws UnsupportedOperationException if an unsupported field's value is non-zero */ public Period(Object period, PeriodType type, Chronology chrono) { super(period, type, chrono); } /** * Constructor used when we trust ourselves. * * @param values the values to use, not null, not cloned * @param type which set of fields this period supports, not null */ private Period(int[] values, PeriodType type) { super(values, type); } //----------------------------------------------------------------------- /** * Get this period as an immutable <code>Period</code> object * by returning <code>this</code>. * * @return <code>this</code> */ public Period toPeriod() { return this; } //----------------------------------------------------------------------- /** * Gets the years field part of the period. * * @

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>return the number of years in the period, zero if unsupported */ public int getYears() { return getPeriodType().getIndexedField(this, PeriodType.YEAR_INDEX); } /** * Gets the months field part of the period. * * @return the number of months in the period, zero if unsupported */ public int getMonths() { return getPeriodType().getIndexedField(this, PeriodType.MONTH_INDEX); } /** * Gets the weeks field part of the period. * * @return the number of weeks in the period, zero if unsupported */ public int getWeeks() { return getPeriodType().getIndexedField(this, PeriodType.WEEK_INDEX); } /** * Gets the days field part of the period. * * @return the number of days in the period, zero if unsupported */ public int getDays() { return getPeriodType().getIndexedField(this, PeriodType.DAY_INDEX); } //----------------------------------------------------------------------- /** * Gets the hours field part of the period. * * @return the number of hours in the period, zero if unsupported */ public int getHours() { return getPeriodType().getIndexedField(this, PeriodType.HOUR_INDEX); } /** * Gets the minutes field part of the period. * * @return the number of minutes in the period, zero if unsupported */ public int getMinutes() { return getPeriodType().getIndexedField(this, PeriodType.MINUTE_INDEX); } /** * Gets the seconds field part of the period. * * @return the number of seconds in the period, zero if unsupported */ public int getSeconds() { return getPeriodType().getIndexedField(this, PeriodType.SECOND_INDEX); } /** * Gets the millis field part of the period. * * @return the number of millis in the period, zero if unsupported */ public int getMillis() { return getPeriodType().getIndexedField(this, PeriodType.MILLI_INDEX); } //----------------------------------------------------------------------- /** * Creates a new Period instance with the same field values but * different PeriodType. * <p> * This period instance is immutable and unaffected by this method call. * * @param type the period type to use, null means standard * @return the new period instance * @throws IllegalArgumentException if the new period won't accept all of the current fields */ public Period withPeriodType(PeriodType type) { type = DateTimeUtils.getPeriodType(type); if (type.equals(getPeriodType())) { return this; } return new Period(this, type); } /** * Creates a new Period instance with the fields from the specified period * copied on top of those from this period. * <p> * This period instance is immutable and unaffected by this method call. * * @param period the period to copy from, null ignored * @return the new period instance * @throws IllegalArgumentException if a field type is

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> unsupported */ public Period withFields(ReadablePeriod period) { if (period == null) { return this; } int[] newValues = getValues(); // cloned newValues = super.mergePeriodInto(newValues, period); return new Period(newValues, getPeriodType()); } //----------------------------------------------------------------------- /** * Creates a new Period instance with the specified field set to a new value. * <p> * This period instance is immutable and unaffected by this method call. * * @param field the field to set, not null * @param value the value to set to * @return the new period instance * @throws IllegalArgumentException if the field type is null or unsupported */ public Period withField(DurationFieldType field, int value) { if (field == null) { throw new IllegalArgumentException("Field must not be null"); } int[] newValues = getValues(); // cloned super.setFieldInto(newValues, field, value); return new Period(newValues, getPeriodType()); } /** * Creates a new Period instance with the valueToAdd added to the specified field. * <p> * This period instance is immutable and unaffected by this method call. * * @param field the field to set, not null * @param value the value to add * @return the new period instance * @throws IllegalArgumentException if the field type is null or unsupported */ public Period withFieldAdded(DurationFieldType field, int value) { if (field == null) { throw new IllegalArgumentException("Field must not be null"); } if (value == 0) { return this; } int[] newValues = getValues(); // cloned super.addFieldInto(newValues, field, value); return new Period(newValues, getPeriodType()); } //----------------------------------------------------------------------- /** * Returns a new period with the specified number of years. * <p> * This period instance is immutable and unaffected by this method call. * * @param years the amount of years to add, may be negative * @return the new period with the increased years * @throws UnsupportedOperationException if the field is not supported */ public Period withYears(int years) { int[] values = getValues(); // cloned getPeriodType().setIndexedField(this, PeriodType.YEAR_INDEX, values, years); return new Period(values, getPeriodType()); } /** * Returns a new period with the specified number of months. * <p> * This period instance is immutable and unaffected by this method call. * * @param months the amount of months to add, may be negative * @return the new period with the increased months * @throws UnsupportedOperationException if the field is not supported */ public Period withMonths(int months) { int[] values = getValues(); // cloned getPeriodType().setIndexedField(this, PeriodType.MONTH_INDEX, values, months); return new Period(values, getPeriodType()); } /** * Returns a new period

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> with the specified number of weeks. * <p> * This period instance is immutable and unaffected by this method call. * * @param weeks the amount of weeks to add, may be negative * @return the new period with the increased weeks * @throws UnsupportedOperationException if the field is not supported */ public Period withWeeks(int weeks) { int[] values = getValues(); // cloned getPeriodType().setIndexedField(this, PeriodType.WEEK_INDEX, values, weeks); return new Period(values, getPeriodType()); } /** * Returns a new period with the specified number of days. * <p> * This period instance is immutable and unaffected by this method call. * * @param days the amount of days to add, may be negative * @return the new period with the increased days * @throws UnsupportedOperationException if the field is not supported */ public Period withDays(int days) { int[] values = getValues(); // cloned getPeriodType().setIndexedField(this, PeriodType.DAY_INDEX, values, days); return new Period(values, getPeriodType()); } /** * Returns a new period with the specified number of hours. * <p> * This period instance is immutable and unaffected by this method call. * * @param hours the amount of hours to add, may be negative * @return the new period with the increased hours * @throws UnsupportedOperationException if the field is not supported */ public Period withHours(int hours) { int[] values = getValues(); // cloned getPeriodType().setIndexedField(this, PeriodType.HOUR_INDEX, values, hours); return new Period(values, getPeriodType()); } /** * Returns a new period with the specified number of minutes. * <p> * This period instance is immutable and unaffected by this method call. * * @param minutes the amount of minutes to add, may be negative * @return the new period with the increased minutes * @throws UnsupportedOperationException if the field is not supported */ public Period withMinutes(int minutes) { int[] values = getValues(); // cloned getPeriodType().setIndexedField(this, PeriodType.MINUTE_INDEX, values, minutes); return new Period(values, getPeriodType()); } /** * Returns a new period with the specified number of seconds. * <p> * This period instance is immutable and unaffected by this method call. * * @param seconds the amount of seconds to add, may be negative * @return the new period with the increased seconds * @throws UnsupportedOperationException if the field is not supported */ public Period withSeconds(int seconds) { int[] values = getValues(); // cloned getPeriodType().setIndexedField(this, PeriodType.SECOND_INDEX, values, seconds); return new Period(values, getPeriodType()); } /** * Returns a new period with the specified number of millis. * <p> * This period instance is immutable and unaffected

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> by this method call. * * @param millis the amount of millis to add, may be negative * @return the new period with the increased millis * @throws UnsupportedOperationException if the field is not supported */ public Period withMillis(int millis) { int[] values = getValues(); // cloned getPeriodType().setIndexedField(this, PeriodType.MILLI_INDEX, values, millis); return new Period(values, getPeriodType()); } //----------------------------------------------------------------------- /** * Returns a new period with the specified period added. * <p> * Each field of the period is added separately. Thus a period of * 2 hours 30 minutes plus 3 hours 40 minutes will produce a result * of 5 hours 70 minutes - see {@link #normalizedStandard()}. * <p> * If the period being added contains a non-zero amount for a field that * is not supported in this period then an exception is thrown. * <p> * This period instance is immutable and unaffected by this method call. * * @param period the period to add, null adds zero and returns this * @return the new updated period * @throws UnsupportedOperationException if any field is not supported * @since 1.5 */ public Period plus(ReadablePeriod period) { if (period == null) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.YEAR_INDEX, values, period.get(DurationFieldType.YEARS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.MONTH_INDEX, values, period.get(DurationFieldType.MONTHS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.WEEK_INDEX, values, period.get(DurationFieldType.WEEKS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.DAY_INDEX, values, period.get(DurationFieldType.DAYS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.HOUR_INDEX, values, period.get(DurationFieldType.HOURS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.MINUTE_INDEX, values, period.get(DurationFieldType.MINUTES_TYPE)); getPeriodType().addIndexedField(this, PeriodType.SECOND_INDEX, values, period.get(DurationFieldType.SECONDS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.MILLI_INDEX, values, period.get(DurationFieldType.MILLIS_TYPE)); return new Period(values, getPeriodType()); } //----------------------------------------------------------------------- /** * Returns a new period with the specified number of years added. * <p> * This period instance is immutable and unaffected by this method call. * * @param years the amount of years to add, may be negative * @return the new period with the increased years * @throws UnsupportedOperationException if the field is not supported */ public Period plusYears(int years) { if (years == 0) {

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.YEAR_INDEX, values, years); return new Period(values, getPeriodType()); } /** * Returns a new period plus the specified number of months added. * <p> * This period instance is immutable and unaffected by this method call. * * @param months the amount of months to add, may be negative * @return the new period plus the increased months * @throws UnsupportedOperationException if the field is not supported */ public Period plusMonths(int months) { if (months == 0) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.MONTH_INDEX, values, months); return new Period(values, getPeriodType()); } /** * Returns a new period plus the specified number of weeks added. * <p> * This period instance is immutable and unaffected by this method call. * * @param weeks the amount of weeks to add, may be negative * @return the new period plus the increased weeks * @throws UnsupportedOperationException if the field is not supported */ public Period plusWeeks(int weeks) { if (weeks == 0) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.WEEK_INDEX, values, weeks); return new Period(values, getPeriodType()); } /** * Returns a new period plus the specified number of days added. * <p> * This period instance is immutable and unaffected by this method call. * * @param days the amount of days to add, may be negative * @return the new period plus the increased days * @throws UnsupportedOperationException if the field is not supported */ public Period plusDays(int days) { if (days == 0) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.DAY_INDEX, values, days); return new Period(values, getPeriodType()); } /** * Returns a new period plus the specified number of hours added. * <p> * This period instance is immutable and unaffected by this method call. * * @param hours the amount of hours to add, may be negative * @return the new period plus the increased hours * @throws UnsupportedOperationException if the field is not supported */ public Period plusHours(int hours) { if (hours == 0) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.HOUR_INDEX, values, hours); return new Period(values, getPeriodType()); } /** * Returns a new period plus the specified number of minutes added. * <p> * This period instance is immutable and unaffected by this method call. *

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * @param minutes the amount of minutes to add, may be negative * @return the new period plus the increased minutes * @throws UnsupportedOperationException if the field is not supported */ public Period plusMinutes(int minutes) { if (minutes == 0) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.MINUTE_INDEX, values, minutes); return new Period(values, getPeriodType()); } /** * Returns a new period plus the specified number of seconds added. * <p> * This period instance is immutable and unaffected by this method call. * * @param seconds the amount of seconds to add, may be negative * @return the new period plus the increased seconds * @throws UnsupportedOperationException if the field is not supported */ public Period plusSeconds(int seconds) { if (seconds == 0) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.SECOND_INDEX, values, seconds); return new Period(values, getPeriodType()); } /** * Returns a new period plus the specified number of millis added. * <p> * This period instance is immutable and unaffected by this method call. * * @param millis the amount of millis to add, may be negative * @return the new period plus the increased millis * @throws UnsupportedOperationException if the field is not supported */ public Period plusMillis(int millis) { if (millis == 0) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.MILLI_INDEX, values, millis); return new Period(values, getPeriodType()); } //----------------------------------------------------------------------- /** * Returns a new period with the specified period subtracted. * <p> * Each field of the period is subtracted separately. Thus a period of * 3 hours 30 minutes minus 2 hours 40 minutes will produce a result * of 1 hour and -10 minutes - see {@link #normalizedStandard()}. * <p> * If the period being added contains a non-zero amount for a field that * is not supported in this period then an exception is thrown. * <p> * This period instance is immutable and unaffected by this method call. * * @param period the period to add, null adds zero and returns this * @return the new updated period * @throws UnsupportedOperationException if any field is not supported * @since 1.5 */ public Period minus(ReadablePeriod period) { if (period == null) { return this; } int[] values = getValues(); // cloned getPeriodType().addIndexedField(this, PeriodType.YEAR_INDEX, values, -period.get(DurationFieldType.YEARS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.MONTH_INDEX, values, -period.get(DurationFieldType.MONTH

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>S_TYPE)); getPeriodType().addIndexedField(this, PeriodType.WEEK_INDEX, values, -period.get(DurationFieldType.WEEKS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.DAY_INDEX, values, -period.get(DurationFieldType.DAYS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.HOUR_INDEX, values, -period.get(DurationFieldType.HOURS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.MINUTE_INDEX, values, -period.get(DurationFieldType.MINUTES_TYPE)); getPeriodType().addIndexedField(this, PeriodType.SECOND_INDEX, values, -period.get(DurationFieldType.SECONDS_TYPE)); getPeriodType().addIndexedField(this, PeriodType.MILLI_INDEX, values, -period.get(DurationFieldType.MILLIS_TYPE)); return new Period(values, getPeriodType()); } //----------------------------------------------------------------------- /** * Returns a new period with the specified number of years taken away. * <p> * This period instance is immutable and unaffected by this method call. * * @param years the amount of years to take away, may be negative * @return the new period with the increased years * @throws UnsupportedOperationException if the field is not supported */ public Period minusYears(int years) { return plusYears(-years); } /** * Returns a new period minus the specified number of months taken away. * <p> * This period instance is immutable and unaffected by this method call. * * @param months the amount of months to take away, may be negative * @return the new period minus the increased months * @throws UnsupportedOperationException if the field is not supported */ public Period minusMonths(int months) { return plusMonths(-months); } /** * Returns a new period minus the specified number of weeks taken away. * <p> * This period instance is immutable and unaffected by this method call. * * @param weeks the amount of weeks to take away, may be negative * @return the new period minus the increased weeks * @throws UnsupportedOperationException if the field is not supported */ public Period minusWeeks(int weeks) { return plusWeeks(-weeks); } /** * Returns a new period minus the specified number of days taken away. * <p> * This period instance is immutable and unaffected by this method call. * * @param days the amount of days to take away, may be negative * @return the new period minus the increased days * @throws UnsupportedOperationException if the field is not supported */ public Period minusDays(int days) { return plusDays(-days); } /** * Returns a new period minus the specified number of hours taken away. * <p> * This period instance is immutable and unaffected by this method call. * * @param hours the amount of hours to take away, may be negative * @return the new period minus the increased hours * @throws

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>millis); } /** * Check that there are no years or months in the period. * * @param destintionType the destination type, not null * @throws UnsupportedOperationException if the period contains years or months */ private void checkYearsAndMonths(String destintionType) { if (getMonths() != 0) { throw new UnsupportedOperationException("Cannot convert to " + destintionType + " as this period contains months and months vary in length"); } if (getYears() != 0) { throw new UnsupportedOperationException("Cannot convert to " + destintionType + " as this period contains years and years vary in length"); } } //----------------------------------------------------------------------- /** * Normalizes this period using standard rules, assuming a 12 month year, * 7 day week, 24 hour day, 60 minute hour and 60 second minute. * <p> * This method allows you to normalize a period. * However to achieve this it makes the assumption that all years are * 12 months, all weeks are 7 days, all days are 24 hours, * all hours are 60 minutes and all minutes are 60 seconds. This is not * true when daylight savings time is considered, and may also not be true * for some chronologies. However, it is included as it is a useful operation * for many applications and business rules. * <p> * If the period contains years or months, then the months will be * normalized to be between 0 and 11. The days field and below will be * normalized as necessary, however this will not overflow into the months * field. Thus a period of 1 year 15 months will normalize to 2 years 3 months. * But a period of 1 month 40 days will remain as 1 month 40 days. * <p> * The result will always have a <code>PeriodType</code> of standard, thus * days will be grouped into weeks. * * @return a normalized period equivalent to this period * @throws ArithmeticException if any field is too large to be represented * @since 1.5 */ public Period normalizedStandard() { return normalizedStandard(PeriodType.standard()); } //----------------------------------------------------------------------- /** * Normalizes this period using standard rules, assuming a 12 month year, * 7 day week, 24 hour day, 60 minute hour and 60 second minute, * providing control over how the result is split into fields. * <p> * This method allows you to normalize a period. * However to achieve this it makes the assumption that all years are * 12 months, all weeks are 7 days, all days are 24 hours, * all hours are 60 minutes and all minutes are 60 seconds. This is not * true when daylight savings time is considered, and may also not be true * for some chronologies. However, it is included as it is a useful operation * for many applications and business rules.

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * <p> * If the period contains years or months, then the months will be * normalized to be between 0 and 11. The days field and below will be * normalized as necessary, however this will not overflow into the months * field. Thus a period of 1 year 15 months will normalize to 2 years 3 months. * But a period of 1 month 40 days will remain as 1 month 40 days. * <p> * The PeriodType parameter controls how the result is created. It allows * you to omit certain fields from the result if desired. For example, * you may not want the result to include weeks, in which case you pass * in <code>PeriodType.yearMonthDayTime()</code>. * * @param type the period type of the new period, null means standard type * @return a normalized period equivalent to this period * @throws ArithmeticException if any field is too large to be represented * @throws UnsupportedOperationException if this period contains non-zero * years or months but the specified period type does not support them * @since 1.5 */ public Period normalizedStandard(PeriodType type) { long millis = getMillis(); // no overflow can happen, even with Integer.MAX_VALUEs millis += (((long) getSeconds()) * ((long) DateTimeConstants.MILLIS_PER_SECOND)); millis += (((long) getMinutes()) * ((long) DateTimeConstants.MILLIS_PER_MINUTE)); millis += (((long) getHours()) * ((long) DateTimeConstants.MILLIS_PER_HOUR)); millis += (((long) getDays()) * ((long) DateTimeConstants.MILLIS_PER_DAY)); millis += (((long) getWeeks()) * ((long) DateTimeConstants.MILLIS_PER_WEEK)); Period result = new Period(millis, DateTimeUtils.getPeriodType(type), ISOChronology.getInstanceUTC()); int years = getYears(); int months = getMonths(); if (years != 0 || months != 0) { years = FieldUtils.safeAdd(years, months / 12); months = months % 12; if (years != 0) { result = result.withYears(years); } if (months != 0) { result = result.withMonths(months); } } return result; } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> } else if (iMode == 's') { offset = standardOffset; } else { offset = 0; } Chronology chrono = ISOChronology.getInstanceUTC(); long millis = chrono.year().set(0, year); millis = chrono.monthOfYear().set(millis, iMonthOfYear); millis = chrono.millisOfDay().set(millis, iMillisOfDay); millis = setDayOfMonth(chrono, millis); if (iDayOfWeek != 0) { millis = setDayOfWeek(chrono, millis); } // Convert from local time to UTC. return millis - offset; } /** * @param standardOffset standard offset just before next recurrence */ public long next(long instant, int standardOffset, int saveMillis) { int offset; if (iMode == 'w') { offset = standardOffset + saveMillis; } else if (iMode == 's') { offset = standardOffset; } else { offset = 0; } // Convert from UTC to local time. instant += offset; Chronology chrono = ISOChronology.getInstanceUTC(); long next = chrono.monthOfYear().set(instant, iMonthOfYear); // Be lenient with millisOfDay. next = chrono.millisOfDay().set(next, 0); next = chrono.millisOfDay().add(next, iMillisOfDay); next = setDayOfMonthNext(chrono, next); if (iDayOfWeek == 0) { if (next <= instant) { next = chrono.year().add(next, 1); next = setDayOfMonthNext(chrono, next); } } else { next = setDayOfWeek(chrono, next); if (next <= instant) { next = chrono.year().add(next, 1); next = chrono.monthOfYear().set(next, iMonthOfYear); next = setDayOfMonthNext(chrono, next); next = setDayOfWeek(chrono, next); } } // Convert from local time to UTC. return next - offset; } /** * @param standardOffset standard offset just before previous recurrence */ public long previous(long instant, int standardOffset, int saveMillis) { int offset; if (iMode == 'w') { offset = standardOffset + saveMillis; } else if (iMode == 's') { offset = standardOffset; } else { offset = 0; } // Convert from UTC to local time. instant += offset; Chronology chrono = ISOChronology.getInstanceUTC(); long prev = chrono.monthOfYear().set(instant, iMonthOfYear); // Be lenient with millisOfDay. prev = chrono.millisOfDay().set(prev, 0); prev = chrono.millisOfDay().add(prev, iMillisOfDay); prev = setDayOfMonthPrevious(chrono, prev); if (iDayOfWeek == 0) { if (prev >= instant) { prev = chrono.year().add(prev, -1); prev = setDayOfMonthPrevious(

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>NameKey + appendNameKey).intern()); } } /** * Extends Recurrence with inclusive year limits. */ private static final class Rule { final Recurrence iRecurrence; final int iFromYear; // inclusive final int iToYear; // inclusive Rule(Recurrence recurrence, int fromYear, int toYear) { iRecurrence = recurrence; iFromYear = fromYear; iToYear = toYear; } public int getFromYear() { return iFromYear; } public int getToYear() { return iToYear; } public OfYear getOfYear() { return iRecurrence.getOfYear(); } public String getNameKey() { return iRecurrence.getNameKey(); } public int getSaveMillis() { return iRecurrence.getSaveMillis(); } public long next(final long instant, int standardOffset, int saveMillis) { Chronology chrono = ISOChronology.getInstanceUTC(); final int wallOffset = standardOffset + saveMillis; long testInstant = instant; int year; if (instant == Long.MIN_VALUE) { year = Integer.MIN_VALUE; } else { year = chrono.year().get(instant + wallOffset); } if (year < iFromYear) { // First advance instant to start of from year. testInstant = chrono.year().set(0, iFromYear) - wallOffset; // Back off one millisecond to account for next recurrence // being exactly at the beginning of the year. testInstant -= 1; } long next = iRecurrence.next(testInstant, standardOffset, saveMillis); if (next > instant) { year = chrono.year().get(next + wallOffset); if (year > iToYear) { // Out of range, return original value. next = instant; } } return next; } } private static final class Transition { private final long iMillis; private final String iNameKey; private final int iWallOffset; private final int iStandardOffset; Transition(long millis, Transition tr) { iMillis = millis; iNameKey = tr.iNameKey; iWallOffset = tr.iWallOffset; iStandardOffset = tr.iStandardOffset; } Transition(long millis, Rule rule, int standardOffset) { iMillis = millis; iNameKey = rule.getNameKey(); iWallOffset = standardOffset + rule.getSaveMillis(); iStandardOffset = standardOffset; } Transition(long millis, String nameKey, int wallOffset, int standardOffset) { iMillis = millis; iNameKey = nameKey; iWallOffset = wallOffset; iStandardOffset = standardOffset; } public long getMillis() { return iMillis; } public String getNameKey() { return iNameKey; } public int getWallOffset() { return iWallOffset; } public int getStandardOffset

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>() { return iStandardOffset; } public int getSaveMillis() { return iWallOffset - iStandardOffset; } /** * There must be a change in the millis, wall offsets or name keys. */ public boolean isTransitionFrom(Transition other) { if (other == null) { return true; } return iMillis > other.iMillis && (iWallOffset != other.iWallOffset || //iStandardOffset != other.iStandardOffset || !(iNameKey.equals(other.iNameKey))); } } private static final class RuleSet { private static final int YEAR_LIMIT; static { // Don't pre-calculate more than 100 years into the future. Almost // all zones will stop pre-calculating far sooner anyhow. Either a // simple DST cycle is detected or the last rule is a fixed // offset. If a zone has a fixed offset set more than 100 years // into the future, then it won't be observed. long now = DateTimeUtils.currentTimeMillis(); YEAR_LIMIT = ISOChronology.getInstanceUTC().year().get(now) + 100; } private int iStandardOffset; private ArrayList<Rule> iRules; // Optional. private String iInitialNameKey; private int iInitialSaveMillis; // Upper limit is exclusive. private int iUpperYear; private OfYear iUpperOfYear; RuleSet() { iRules = new ArrayList<Rule>(10); iUpperYear = Integer.MAX_VALUE; } /** * Copy constructor. */ RuleSet(RuleSet rs) { iStandardOffset = rs.iStandardOffset; iRules = new ArrayList<Rule>(rs.iRules); iInitialNameKey = rs.iInitialNameKey; iInitialSaveMillis = rs.iInitialSaveMillis; iUpperYear = rs.iUpperYear; iUpperOfYear = rs.iUpperOfYear; } public int getStandardOffset() { return iStandardOffset; } public void setStandardOffset(int standardOffset) { iStandardOffset = standardOffset; } public void setFixedSavings(String nameKey, int saveMillis) { iInitialNameKey = nameKey; iInitialSaveMillis = saveMillis; } public void addRule(Rule rule) { if (!iRules.contains(rule)) { iRules.add(rule); } } public void setUpperLimit(int year, OfYear ofYear) { iUpperYear = year; iUpperOfYear = ofYear; } /** * Returns a transition at firstMillis with the first name key and * offsets for this rule set. This method may return null. * * @param firstMillis millis of first transition */ public Transition firstTransition(final long firstMillis) { if (iInitialNameKey != null) { // Initial zone info explicitly set, so don't search the rules. return new Transition(firstMillis, iInitialNameKey, i

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>StandardOffset + iInitialSaveMillis, iStandardOffset); } // Make a copy before we destroy the rules. ArrayList<Rule> copy = new ArrayList<Rule>(iRules); // Iterate through all the transitions until firstMillis is // reached. Use the name key and savings for whatever rule reaches // the limit. long millis = Long.MIN_VALUE; int saveMillis = 0; Transition first = null; Transition next; while ((next = nextTransition(millis, saveMillis)) != null) { millis = next.getMillis(); if (millis == firstMillis) { first = new Transition(firstMillis, next); break; } if (millis > firstMillis) { if (first == null) { // Find first rule without savings. This way a more // accurate nameKey is found even though no rule // extends to the RuleSet's lower limit. for (Rule rule : copy) { if (rule.getSaveMillis() == 0) { first = new Transition(firstMillis, rule, iStandardOffset); break; } } } if (first == null) { // Found no rule without savings. Create a transition // with no savings anyhow, and use the best available // name key. first = new Transition(firstMillis, next.getNameKey(), iStandardOffset, iStandardOffset); } break; } // Set first to the best transition found so far, but next // iteration may find something closer to lower limit. first = new Transition(firstMillis, next); saveMillis = next.getSaveMillis(); } iRules = copy; return first; } /** * Returns null if RuleSet is exhausted or upper limit reached. Calling * this method will throw away rules as they each become * exhausted. Copy the RuleSet before using it to compute transitions. * * Returned transition may be a duplicate from previous * transition. Caller must call isTransitionFrom to filter out * duplicates. * * @param saveMillis savings before next transition */ public Transition nextTransition(final long instant, final int saveMillis) { Chronology chrono = ISOChronology.getInstanceUTC(); // Find next matching rule. Rule nextRule = null; long nextMillis = Long.MAX_VALUE; Iterator<Rule> it = iRules.iterator(); while (it.hasNext()) { Rule rule = it.next(); long next = rule.next(instant, iStandardOffset, saveMillis); if (next <= instant) { it.remove(); continue; } // Even if next is same as previous next, choose the rule // in order for more recently added rules to override. if (next <= nextMillis) { // Found a better match. nextRule = rule; nextMillis = next; } } if (nextRule == null) { return null; } // Stop precalculating if year reaches some arbitrary limit. if (chrono.year().get(nextMillis) >= YEAR_LIMIT

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>get(i); if (!tr.isTransitionFrom(last)) { throw new IllegalArgumentException(id); } trans[i] = tr.getMillis(); wallOffsets[i] = tr.getWallOffset(); standardOffsets[i] = tr.getStandardOffset(); nameKeys[i] = tr.getNameKey(); last = tr; } // Some timezones (Australia) have the same name key for // summer and winter which messes everything up. Fix it here. String[] zoneNameData = new String[5]; String[][] zoneStrings = new DateFormatSymbols(Locale.ENGLISH).getZoneStrings(); for (int j = 0; j < zoneStrings.length; j++) { String[] set = zoneStrings[j]; if (set != null && set.length == 5 && id.equals(set[0])) { zoneNameData = set; } } Chronology chrono = ISOChronology.getInstanceUTC(); for (int i = 0; i < nameKeys.length - 1; i++) { String curNameKey = nameKeys[i]; String nextNameKey = nameKeys[i + 1]; long curOffset = wallOffsets[i]; long nextOffset = wallOffsets[i + 1]; long curStdOffset = standardOffsets[i]; long nextStdOffset = standardOffsets[i + 1]; Period p = new Period(trans[i], trans[i + 1], PeriodType.yearMonthDay(), chrono); if (curOffset != nextOffset && curStdOffset == nextStdOffset && curNameKey.equals(nextNameKey) && p.getYears() == 0 && p.getMonths() > 4 && p.getMonths() < 8 && curNameKey.equals(zoneNameData[2]) && curNameKey.equals(zoneNameData[4])) { if (ZoneInfoCompiler.verbose()) { System.out.println("Fixing duplicate name key - " + nextNameKey); System.out.println(" - " + new DateTime(trans[i], chrono) + " - " + new DateTime(trans[i + 1], chrono)); } if (curOffset > nextOffset) { nameKeys[i] = (curNameKey + "-Summer").intern(); } else if (curOffset < nextOffset) { nameKeys[i + 1] = (nextNameKey + "-Summer").intern(); i++; } } } if (tailZone != null) { if (tailZone.iStartRecurrence.getNameKey() .equals(tailZone.iEndRecurrence.getNameKey())) { if (ZoneInfoCompiler.verbose()) { System.out.println("Fixing duplicate recurrent name key - " + tailZone.iStartRecurrence.getNameKey()); } if (tailZone.iStartRecurrence.getSaveMillis() > 0) { tailZone = new DSTZone( tailZone.getID(), tailZone.

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> iField.getMinimumValue(); } public int getMinimumValue(long instant) { long localInstant = iZone.convertUTCToLocal(instant); return iField.getMinimumValue(localInstant); } public int getMinimumValue(ReadablePartial instant) { return iField.getMinimumValue(instant); } public int getMinimumValue(ReadablePartial instant, int[] values) { return iField.getMinimumValue(instant, values); } public int getMaximumValue() { return iField.getMaximumValue(); } public int getMaximumValue(long instant) { long localInstant = iZone.convertUTCToLocal(instant); return iField.getMaximumValue(localInstant); } public int getMaximumValue(ReadablePartial instant) { return iField.getMaximumValue(instant); } public int getMaximumValue(ReadablePartial instant, int[] values) { return iField.getMaximumValue(instant, values); } public int getMaximumTextLength(Locale locale) { return iField.getMaximumTextLength(locale); } public int getMaximumShortTextLength(Locale locale) { return iField.getMaximumShortTextLength(locale); } private int getOffsetToAdd(long instant) { int offset = this.iZone.getOffset(instant); long sum = instant + offset; // If there is a sign change, but the two values have the same sign... if ((instant ^ sum) < 0 && (instant ^ offset) >= 0) { throw new ArithmeticException("Adding time zone offset caused overflow"); } return offset; } } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2005 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time.chrono; import org.joda.time.DateTimeField; import org.joda.time.DateTimeFieldType; import org.joda.time.ReadablePartial; import org.joda.time.field.DecoratedDateTimeField; import org.joda.time.field.FieldUtils; /** * This field is not publicy exposed by ISOChronology, but rather it is used to * build the yearOfCentury and centuryOfEra fields. It merely drops the sign of * the year. * * @author Brian S O'Neill * @see GJYearOfEraDateTimeField * @since 1.0 */ class ISOYearOfEraDateTimeField extends DecoratedDateTimeField { private static final long serialVersionUID = 7037524068969447317L; /** * Singleton instance */ static final DateTimeField INSTANCE = new ISOYearOfEraDateTimeField(); /** * Restricted constructor. */ private ISOYearOfEraDateTimeField() { super(GregorianChronology.getInstanceUTC().year(), DateTimeFieldType.yearOfEra()); } public int get(long instant) { int year = getWrappedField().get(instant); return year < 0 ? -year : year; } public long add(long instant, int years) { return getWrappedField().add(instant, years); } public long add(long instant, long years) { return getWrappedField().add(instant, years); } public long addWrapField(long instant, int years) { return getWrappedField().addWrapField(instant, years); } public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int years) { return getWrappedField().addWrapField(instant, fieldIndex, values, years); } public int getDifference(long minuendInstant, long subtrahendInstant) { return getWrappedField().getDifference(minuendInstant, subtrahendInstant); } public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) { return getWrappedField().getDifferenceAsLong(minuendInstant, subtrahendInstant); } public long set(long instant, int year) { Field

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>remainder(instant + 3 * DateTimeConstants.MILLIS_PER_DAY); } public int getMinimumValue() { return 1; } public int getMaximumValue() { return 53; } public int getMaximumValue(long instant) { int weekyear = iChronology.getWeekyear(instant); return iChronology.getWeeksInYear(weekyear); } public int getMaximumValue(ReadablePartial partial) { if (partial.isSupported(DateTimeFieldType.weekyear())) { int weekyear = partial.get(DateTimeFieldType.weekyear()); return iChronology.getWeeksInYear(weekyear); } return 53; } public int getMaximumValue(ReadablePartial partial, int[] values) { int size = partial.size(); for (int i = 0; i < size; i++) { if (partial.getFieldType(i) == DateTimeFieldType.weekyear()) { int weekyear = values[i]; return iChronology.getWeeksInYear(weekyear); } } return 53; } protected int getMaximumValueForSet(long instant, int value) { return value > 52 ? getMaximumValue(instant) : 52; } /** * Serialization singleton */ private Object readResolve() { return iChronology.weekOfWeekyear(); } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2005 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time.chrono; import org.joda.time.DateTimeFieldType; import org.joda.time.DurationField; import org.joda.time.ReadablePartial; import org.joda.time.field.PreciseDurationDateTimeField; /** * Provides time calculations for the day of the year component of time. * * @author Guy Allard * @author Stephen Colebourne * @author Brian S O'Neill * @since 1.1, refactored from GJDayOfYearDateTimeField */ final class BasicDayOfYearDateTimeField extends PreciseDurationDateTimeField { private static final long serialVersionUID = -6821236822336841037L; private final BasicChronology iChronology; /** * Restricted constructor */ BasicDayOfYearDateTimeField(BasicChronology chronology, DurationField days) { super(DateTimeFieldType.dayOfYear(), days); iChronology = chronology; } /** * Get the day of the year component of the specified time instant. * * @param instant the time instant in millis to query. * @return the day of the year extracted from the input. */ public int get(long instant) { return iChronology.getDayOfYear(instant); } public DurationField getRangeDurationField() { return iChronology.years(); } public int getMinimumValue() { return 1; } public int getMaximumValue() { return iChronology.getDaysInYearMax(); } public int getMaximumValue(long instant) { int year = iChronology.getYear(instant); return iChronology.getDaysInYear(year); } public int getMaximumValue(ReadablePartial partial) { if (partial.isSupported(DateTimeFieldType.year())) { int year = partial.get(DateTimeFieldType.year()); return iChronology.getDaysInYear(year); } return iChronology.getDaysInYearMax(); } public int getMaximumValue(ReadablePartial partial, int[] values) { int size = partial.size(); for (int i = 0; i < size; i++) { if (partial.getFieldType(i) == DateTime

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>FieldType.year()) { int year = values[i]; return iChronology.getDaysInYear(year); } } return iChronology.getDaysInYearMax(); } protected int getMaximumValueForSet(long instant, int value) { int maxLessOne = iChronology.getDaysInYearMax() - 1; return (value > maxLessOne || value < 1) ? getMaximumValue(instant) : maxLessOne; } /** * Serialization singleton */ private Object readResolve() { return iChronology.dayOfYear(); } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> } /** * Sets the current time to return the system time plus an offset. * <p> * This method changes the behaviour of {@link #currentTimeMillis()}. * Whenever the current time is queried, {@link System#currentTimeMillis()} is used * and then offset by adding the millisecond value specified here. * * @param offsetMillis the fixed millisecond time to use * @throws SecurityException if the application does not have sufficient security rights */ public static final void setCurrentMillisOffset(long offsetMillis) throws SecurityException { checkPermission(); if (offsetMillis == 0) { cMillisProvider = SYSTEM_MILLIS_PROVIDER; } else { cMillisProvider = new OffsetMillisProvider(offsetMillis); } } /** * Sets the provider of the current time to class specified. * <p> * This method changes the behaviour of {@link #currentTimeMillis()}. * Whenever the current time is queried, the specified class will be called. * * @param millisProvider the provider of the current time to use, not null * @throws SecurityException if the application does not have sufficient security rights * @since 2.0 */ public static final void setCurrentMillisProvider(MillisProvider millisProvider) throws SecurityException { if (millisProvider == null) { throw new IllegalArgumentException("The MillisProvider must not be null"); } checkPermission(); cMillisProvider = millisProvider; } /** * Checks whether the provider may be changed using permission 'CurrentTime.setProvider'. * * @throws SecurityException if the provider may not be changed */ private static void checkPermission() throws SecurityException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new JodaTimePermission("CurrentTime.setProvider")); } } //----------------------------------------------------------------------- /** * Gets the millisecond instant from the specified instant object handling null. * <p> * If the instant object is <code>null</code>, the {@link #currentTimeMillis()} * will be returned. Otherwise, the millis from the object are returned. * * @param instant the instant to examine, null means now * @return the time in milliseconds from 1970-01-01T00:00:00Z */ public static final long getInstantMillis(ReadableInstant instant) { if (instant == null) { return DateTimeUtils.currentTimeMillis(); } return instant.getMillis(); } //----------------------------------------------------------------------- /** * Gets the chronology from the specified instant object handling null. * <p> * If the instant object is <code>null</code>, or the instant's chronology is * <code>null</code>, {@link ISOChronology#getInstance()} will be returned. * Otherwise, the chronology from the object is returned. * * @param instant the instant to examine, null means ISO in the default zone * @return the chronology, never null */ public static final Chronology getInstantChronology(ReadableInstant instant

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>) { if (instant == null) { return ISOChronology.getInstance(); } Chronology chrono = instant.getChronology(); if (chrono == null) { return ISOChronology.getInstance(); } return chrono; } //----------------------------------------------------------------------- /** * Gets the chronology from the specified instant based interval handling null. * <p> * The chronology is obtained from the start if that is not null, or from the * end if the start is null. The result is additionally checked, and if still * null then {@link ISOChronology#getInstance()} will be returned. * * @param start the instant to examine and use as the primary source of the chronology * @param end the instant to examine and use as the secondary source of the chronology * @return the chronology, never null */ public static final Chronology getIntervalChronology(ReadableInstant start, ReadableInstant end) { Chronology chrono = null; if (start != null) { chrono = start.getChronology(); } else if (end != null) { chrono = end.getChronology(); } if (chrono == null) { chrono = ISOChronology.getInstance(); } return chrono; } //----------------------------------------------------------------------- /** * Gets the chronology from the specified interval object handling null. * <p> * If the interval object is <code>null</code>, or the interval's chronology is * <code>null</code>, {@link ISOChronology#getInstance()} will be returned. * Otherwise, the chronology from the object is returned. * * @param interval the interval to examine, null means ISO in the default zone * @return the chronology, never null */ public static final Chronology getIntervalChronology(ReadableInterval interval) { if (interval == null) { return ISOChronology.getInstance(); } Chronology chrono = interval.getChronology(); if (chrono == null) { return ISOChronology.getInstance(); } return chrono; } //----------------------------------------------------------------------- /** * Gets the interval handling null. * <p> * If the interval is <code>null</code>, an interval representing now * to now in the {@link ISOChronology#getInstance() ISOChronology} * will be returned. Otherwise, the interval specified is returned. * * @param interval the interval to use, null means now to now * @return the interval, never null * @since 1.1 */ public static final ReadableInterval getReadableInterval(ReadableInterval interval) { if (interval == null) { long now = DateTimeUtils.currentTimeMillis(); interval = new Interval(now, now); } return interval; } //----------------------------------------------------------------------- /** * Gets the chronology handling null. * <p> * If the chronology is <code>null</code>, {@link ISOChronology#getInstance()}

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * will be returned. Otherwise, the chronology is returned. * * @param chrono the chronology to use, null means ISO in the default zone * @return the chronology, never null */ public static final Chronology getChronology(Chronology chrono) { if (chrono == null) { return ISOChronology.getInstance(); } return chrono; } //----------------------------------------------------------------------- /** * Gets the zone handling null. * <p> * If the zone is <code>null</code>, {@link DateTimeZone#getDefault()} * will be returned. Otherwise, the zone specified is returned. * * @param zone the time zone to use, null means the default zone * @return the time zone, never null */ public static final DateTimeZone getZone(DateTimeZone zone) { if (zone == null) { return DateTimeZone.getDefault(); } return zone; } //----------------------------------------------------------------------- /** * Gets the period type handling null. * <p> * If the zone is <code>null</code>, {@link PeriodType#standard()} * will be returned. Otherwise, the type specified is returned. * * @param type the time zone to use, null means the standard type * @return the type to use, never null */ public static final PeriodType getPeriodType(PeriodType type) { if (type == null) { return PeriodType.standard(); } return type; } //----------------------------------------------------------------------- /** * Gets the millisecond duration from the specified duration object handling null. * <p> * If the duration object is <code>null</code>, zero will be returned. * Otherwise, the millis from the object are returned. * * @param duration the duration to examine, null means zero * @return the duration in milliseconds */ public static final long getDurationMillis(ReadableDuration duration) { if (duration == null) { return 0L; } return duration.getMillis(); } //----------------------------------------------------------------------- /** * Checks whether the partial is contiguous. * <p> * A partial is contiguous if one field starts where another ends. * <p> * For example <code>LocalDate</code> is contiguous because DayOfMonth has * the same range (Month) as the unit of the next field (MonthOfYear), and * MonthOfYear has the same range (Year) as the unit of the next field (Year). * <p> * Similarly, <code>LocalTime</code> is contiguous, as it consists of * MillisOfSecond, SecondOfMinute, MinuteOfHour and HourOfDay (note how * the names of each field 'join up'). * <p> * However, a Year/HourOfDay partial is not contiguous because the range * field Day is not equal to the next field Year. * Similarly, a DayOfWeek/DayOfMonth partial is not contiguous because * the range Month is not equal to the next field Day. * * @param partial the partial to check * @

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>return true if the partial is contiguous * @throws IllegalArgumentException if the partial is null * @since 1.1 */ public static final boolean isContiguous(ReadablePartial partial) { if (partial == null) { throw new IllegalArgumentException("Partial must not be null"); } DurationFieldType lastType = null; for (int i = 0; i < partial.size(); i++) { DateTimeField loopField = partial.getField(i); if (i > 0) { if (loopField.getRangeDurationField().getType() != lastType) { return false; } } lastType = loopField.getDurationField().getType(); } return true; } //----------------------------------------------------------------------- /** * Gets the {@link DateFormatSymbols} based on the given locale. * <p> * If JDK 6 or newer is being used, DateFormatSymbols.getInstance(locale) will * be used in order to allow the use of locales defined as extensions. * Otherwise, new DateFormatSymbols(locale) will be used. * See JDK 6 {@link DateFormatSymbols} for further information. * * @param locale the {@link Locale} used to get the correct {@link DateFormatSymbols} * @return the symbols * @since 2.0 */ public static final DateFormatSymbols getDateFormatSymbols(Locale locale) { try { Method method = DateFormatSymbols.class.getMethod("getInstance", new Class[] {Locale.class}); return (DateFormatSymbols) method.invoke(null, new Object[] {locale}); } catch (Exception ex) { return new DateFormatSymbols(locale); } } //----------------------------------------------------------------------- /** * A millisecond provider, allowing control of the system clock. * * @author Stephen Colebourne * @since 2.0 (previously private) */ public static interface MillisProvider { /** * Gets the current time. * <p> * Implementations of this method must be thread-safe. * * @return the current time in milliseconds */ long getMillis(); } /** * System millis provider. */ static class SystemMillisProvider implements MillisProvider { /** * Gets the current time. * @return the current time in millis */ public long getMillis() { return System.currentTimeMillis(); } } /** * Fixed millisecond provider. */ static class FixedMillisProvider implements MillisProvider { /** The fixed millis value. */ private final long iMillis; /** * Constructor. * @param offsetMillis the millis offset */ FixedMillisProvider(long fixedMillis) { iMillis = fixedMillis; } /** * Gets the current time. * @return the current time in millis */ public long getMillis() { return iMillis; } } /** * Offset from system millis provider. */ static class OffsetMillisProvider implements MillisProvider { /** The millis offset. */ private final long iMillis; /** * Constructor.

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * @param offsetMillis the millis offset */ OffsetMillisProvider(long offsetMillis) { iMillis = offsetMillis; } /** * Gets the current time. * @return the current time in millis */ public long getMillis() { return System.currentTimeMillis() + iMillis; } } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2005 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time; /** * Defines a time period specified in terms of individual duration fields * such as years and days. * <p> * The implementation of this interface may be mutable or immutable. This * interface only gives access to retrieve data, never to change it. * <p> * Periods are split up into multiple fields, for example days and seconds. * Implementations are not required to evenly distribute the values across the fields. * The value for each field may be positive or negative. * <p> * When a time period is added to an instant, the effect is to add each field in turn. * For example, a time period could be defined as 3 months, 2 days and -1 hours. * In most circumstances this would be the same as 3 months, 1 day, and 23 hours. * However, when adding across a daylight savings boundary, a day may be 23 or 25 hours long. * Thus, the time period is always added field by field to the datetime. * <p> * Periods are independent of chronology, and can only be treated as durations * when paired with a time via an interval. * * @see ReadableDuration * @see ReadableInterval * @author Brian S O'Neill * @author Stephen Colebourne * @since 1.0 */ public interface ReadablePeriod { /** * Gets the period type that defines which fields are included in the period. * * @return the period type */ PeriodType getPeriodType(); /** * Gets the number of fields that this period supports. * * @return the number of fields supported */ int size(); /** * Gets the field type at the specified index. * * @param index the index to retrieve * @return the field at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ DurationFieldType getFieldType(int index); /** * Gets the value at the specified index. * * @param index the index to retrieve * @return the value of the field at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ int getValue(int index); /** * Gets the value of one of the fields. * <p

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2009 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import org.joda.time.field.FieldUtils; /** * Controls a period implementation by specifying which duration fields are to be used. * <p> * The following implementations are provided: * <ul> * <li>Standard - years, months, weeks, days, hours, minutes, seconds, millis * <li>YearMonthDayTime - years, months, days, hours, minutes, seconds, millis * <li>YearMonthDay - years, months, days * <li>YearWeekDayTime - years, weeks, days, hours, minutes, seconds, millis * <li>YearWeekDay - years, weeks, days * <li>YearDayTime - years, days, hours, minutes, seconds, millis * <li>YearDay - years, days, hours * <li>DayTime - days, hours, minutes, seconds, millis * <li>Time - hours, minutes, seconds, millis * <li>plus one for each single type * </ul> * * <p> * PeriodType is thread-safe and immutable, and all subclasses must be as well. * * @author Brian S O'Neill * @author Stephen Colebourne * @since 1.0 */ public class PeriodType implements Serializable { /** Serialization version */ private static final long serialVersionUID = 2274324892792009998L; /** Cache of all the known types. */ private static final Map<PeriodType, Object> cTypes = new HashMap<PeriodType, Object>(32); static int YEAR_INDEX = 0; static int MONTH_INDEX = 1; static int WEEK_INDEX = 2; static int DAY_INDEX = 3; static int HOUR_INDEX = 4; static int MINUTE_INDEX = 5; static int SECOND_INDEX = 6; static int MILLI_INDEX = 7; private static PeriodType cStandard; private static PeriodType cYMDTime; private static Period

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>Type cYMD; private static PeriodType cYWDTime; private static PeriodType cYWD; private static PeriodType cYDTime; private static PeriodType cYD; private static PeriodType cDTime; private static PeriodType cTime; private static PeriodType cYears; private static PeriodType cMonths; private static PeriodType cWeeks; private static PeriodType cDays; private static PeriodType cHours; private static PeriodType cMinutes; private static PeriodType cSeconds; private static PeriodType cMillis; /** * Gets a type that defines all standard fields. * <ul> * <li>years * <li>months * <li>weeks * <li>days * <li>hours * <li>minutes * <li>seconds * <li>milliseconds * </ul> * * @return the period type */ public static PeriodType standard() { PeriodType type = cStandard; if (type == null) { type = new PeriodType( "Standard", new DurationFieldType[] { DurationFieldType.years(), DurationFieldType.months(), DurationFieldType.weeks(), DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds(), DurationFieldType.millis(), }, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, } ); cStandard = type; } return type; } /** * Gets a type that defines all standard fields except weeks. * <ul> * <li>years * <li>months * <li>days * <li>hours * <li>minutes * <li>seconds * <li>milliseconds * </ul> * * @return the period type */ public static PeriodType yearMonthDayTime() { PeriodType type = cYMDTime; if (type == null) { type = new PeriodType( "YearMonthDayTime", new DurationFieldType[] { DurationFieldType.years(), DurationFieldType.months(), DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds(), DurationFieldType.millis(), }, new int[] { 0, 1, -1, 2, 3, 4, 5, 6, } ); cYMDTime = type; } return type; } /** * Gets a type that defines the year, month and day fields. * <ul> * <li>years * <li>months * <li>days * </ul> * * @return the period type * @since 1.1 */ public static PeriodType yearMonthDay() { PeriodType type = cYMD; if (type == null) { type = new PeriodType( "YearMonthDay", new DurationFieldType[] { DurationFieldType.years(), DurationFieldType.months(), DurationFieldType.days(), }, new int

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>[] { 0, 1, -1, 2, -1, -1, -1, -1, } ); cYMD = type; } return type; } /** * Gets a type that defines all standard fields except months. * <ul> * <li>years * <li>weeks * <li>days * <li>hours * <li>minutes * <li>seconds * <li>milliseconds * </ul> * * @return the period type */ public static PeriodType yearWeekDayTime() { PeriodType type = cYWDTime; if (type == null) { type = new PeriodType( "YearWeekDayTime", new DurationFieldType[] { DurationFieldType.years(), DurationFieldType.weeks(), DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds(), DurationFieldType.millis(), }, new int[] { 0, -1, 1, 2, 3, 4, 5, 6, } ); cYWDTime = type; } return type; } /** * Gets a type that defines year, week and day fields. * <ul> * <li>years * <li>weeks * <li>days * </ul> * * @return the period type * @since 1.1 */ public static PeriodType yearWeekDay() { PeriodType type = cYWD; if (type == null) { type = new PeriodType( "YearWeekDay", new DurationFieldType[] { DurationFieldType.years(), DurationFieldType.weeks(), DurationFieldType.days(), }, new int[] { 0, -1, 1, 2, -1, -1, -1, -1, } ); cYWD = type; } return type; } /** * Gets a type that defines all standard fields except months and weeks. * <ul> * <li>years * <li>days * <li>hours * <li>minutes * <li>seconds * <li>milliseconds * </ul> * * @return the period type */ public static PeriodType yearDayTime() { PeriodType type = cYDTime; if (type == null) { type = new PeriodType( "YearDayTime", new DurationFieldType[] { DurationFieldType.years(), DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds(), DurationFieldType.millis(), }, new int[] { 0, -1, -1, 1, 2, 3, 4, 5, } ); cYDTime = type; } return type; } /** * Gets a type that defines the year and day fields. * <ul> * <li>years * <li>days * </ul> * * @return the period type

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * @since 1.1 */ public static PeriodType yearDay() { PeriodType type = cYD; if (type == null) { type = new PeriodType( "YearDay", new DurationFieldType[] { DurationFieldType.years(), DurationFieldType.days(), }, new int[] { 0, -1, -1, 1, -1, -1, -1, -1, } ); cYD = type; } return type; } /** * Gets a type that defines all standard fields from days downwards. * <ul> * <li>days * <li>hours * <li>minutes * <li>seconds * <li>milliseconds * </ul> * * @return the period type */ public static PeriodType dayTime() { PeriodType type = cDTime; if (type == null) { type = new PeriodType( "DayTime", new DurationFieldType[] { DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds(), DurationFieldType.millis(), }, new int[] { -1, -1, -1, 0, 1, 2, 3, 4, } ); cDTime = type; } return type; } /** * Gets a type that defines all standard time fields. * <ul> * <li>hours * <li>minutes * <li>seconds * <li>milliseconds * </ul> * * @return the period type */ public static PeriodType time() { PeriodType type = cTime; if (type == null) { type = new PeriodType( "Time", new DurationFieldType[] { DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds(), DurationFieldType.millis(), }, new int[] { -1, -1, -1, -1, 0, 1, 2, 3, } ); cTime = type; } return type; } /** * Gets a type that defines just the years field. * * @return the period type */ public static PeriodType years() { PeriodType type = cYears; if (type == null) { type = new PeriodType( "Years", new DurationFieldType[] { DurationFieldType.years() }, new int[] { 0, -1, -1, -1, -1, -1, -1, -1, } ); cYears = type; } return type; } /** * Gets a type that defines just the months field. * * @return the period type */ public static PeriodType months() { PeriodType type = cMonths; if (type == null) { type = new PeriodType( "Months", new DurationFieldType[] { DurationFieldType.months() }, new int[] { -1, 0, -1, -1, -1, -1, -1, -1

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>, } ); cMonths = type; } return type; } /** * Gets a type that defines just the weeks field. * * @return the period type */ public static PeriodType weeks() { PeriodType type = cWeeks; if (type == null) { type = new PeriodType( "Weeks", new DurationFieldType[] { DurationFieldType.weeks() }, new int[] { -1, -1, 0, -1, -1, -1, -1, -1, } ); cWeeks = type; } return type; } /** * Gets a type that defines just the days field. * * @return the period type */ public static PeriodType days() { PeriodType type = cDays; if (type == null) { type = new PeriodType( "Days", new DurationFieldType[] { DurationFieldType.days() }, new int[] { -1, -1, -1, 0, -1, -1, -1, -1, } ); cDays = type; } return type; } /** * Gets a type that defines just the hours field. * * @return the period type */ public static PeriodType hours() { PeriodType type = cHours; if (type == null) { type = new PeriodType( "Hours", new DurationFieldType[] { DurationFieldType.hours() }, new int[] { -1, -1, -1, -1, 0, -1, -1, -1, } ); cHours = type; } return type; } /** * Gets a type that defines just the minutes field. * * @return the period type */ public static PeriodType minutes() { PeriodType type = cMinutes; if (type == null) { type = new PeriodType( "Minutes", new DurationFieldType[] { DurationFieldType.minutes() }, new int[] { -1, -1, -1, -1, -1, 0, -1, -1, } ); cMinutes = type; } return type; } /** * Gets a type that defines just the seconds field. * * @return the period type */ public static PeriodType seconds() { PeriodType type = cSeconds; if (type == null) { type = new PeriodType( "Seconds", new DurationFieldType[] { DurationFieldType.seconds() }, new int[] { -1, -1, -1, -1, -1, -1, 0, -1, } ); cSeconds = type; } return type; } /** * Gets a type that defines just the millis field. * * @return the period type */ public static PeriodType millis() { PeriodType type = cMillis; if (type == null) { type = new PeriodType( "Millis", new DurationFieldType[] { DurationFieldType.millis() }, new int[]

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> { -1, -1, -1, -1, -1, -1, -1, 0, } ); cMillis = type; } return type; } /** * Gets a period type that contains the duration types of the array. * <p> * Only the 8 standard duration field types are supported. * * @param types the types to include in the array. * @return the period type * @since 1.1 */ public static synchronized PeriodType forFields(DurationFieldType[] types) { if (types == null || types.length == 0) { throw new IllegalArgumentException("Types array must not be null or empty"); } for (int i = 0; i < types.length; i++) { if (types[i] == null) { throw new IllegalArgumentException("Types array must not contain null"); } } Map<PeriodType, Object> cache = cTypes; if (cache.isEmpty()) { cache.put(standard(), standard()); cache.put(yearMonthDayTime(), yearMonthDayTime()); cache.put(yearMonthDay(), yearMonthDay()); cache.put(yearWeekDayTime(), yearWeekDayTime()); cache.put(yearWeekDay(), yearWeekDay()); cache.put(yearDayTime(), yearDayTime()); cache.put(yearDay(), yearDay()); cache.put(dayTime(), dayTime()); cache.put(time(), time()); cache.put(years(), years()); cache.put(months(), months()); cache.put(weeks(), weeks()); cache.put(days(), days()); cache.put(hours(), hours()); cache.put(minutes(), minutes()); cache.put(seconds(), seconds()); cache.put(millis(), millis()); } PeriodType inPartType = new PeriodType(null, types, null); Object cached = cache.get(inPartType); if (cached instanceof PeriodType) { return (PeriodType) cached; } if (cached != null) { throw new IllegalArgumentException("PeriodType does not support fields: " + cached); } PeriodType type = standard(); List<DurationFieldType> list = new ArrayList<DurationFieldType>(Arrays.asList(types)); if (list.remove(DurationFieldType.years()) == false) { type = type.withYearsRemoved(); } if (list.remove(DurationFieldType.months()) == false) { type = type.withMonthsRemoved(); } if (list.remove(DurationFieldType.weeks()) == false) { type = type.withWeeksRemoved(); } if (list.remove(DurationFieldType.days()) == false) { type = type.withDaysRemoved(); } if (list.remove(DurationFieldType.hours()) == false) { type = type.withHoursRemoved(); } if (list.remove(DurationFieldType.minutes()) == false) { type = type.withMinutesRemoved(); } if (list.remove(DurationFieldType.seconds()) == false) {

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> type = type.withSecondsRemoved(); } if (list.remove(DurationFieldType.millis()) == false) { type = type.withMillisRemoved(); } if (list.size() > 0) { cache.put(inPartType, list); throw new IllegalArgumentException("PeriodType does not support fields: " + list); } // recheck cache in case initial array order was wrong PeriodType checkPartType = new PeriodType(null, type.iTypes, null); PeriodType checkedType = (PeriodType) cache.get(checkPartType); if (checkedType != null) { cache.put(inPartType, checkedType); return checkedType; } cache.put(inPartType, type); return type; } //----------------------------------------------------------------------- /** The name of the type */ private final String iName; /** The array of types */ private final DurationFieldType[] iTypes; /** The array of indices */ private final int[] iIndices; /** * Constructor. * * @param name the name * @param types the types * @param indices the indices */ protected PeriodType(String name, DurationFieldType[] types, int[] indices) { super(); iName = name; iTypes = types; iIndices = indices; } //----------------------------------------------------------------------- /** * Gets the name of the period type. * * @return the name */ public String getName() { return iName; } /** * Gets the number of fields in the period type. * * @return the number of fields */ public int size() { return iTypes.length; } /** * Gets the field type by index. * * @param index the index to retrieve * @return the field type * @throws IndexOutOfBoundsException if the index is invalid */ public DurationFieldType getFieldType(int index) { return iTypes[index]; } /** * Checks whether the field specified is supported by this period. * * @param type the type to check, may be null which returns false * @return true if the field is supported */ public boolean isSupported(DurationFieldType type) { return (indexOf(type) >= 0); } /** * Gets the index of the field in this period. * * @param type the type to check, may be null which returns -1 * @return the index of -1 if not supported */ public int indexOf(DurationFieldType type) { for (int i = 0, isize = size(); i < isize; i++) { if (iTypes[i] == type) { return i; } } return -1; } /** * Gets a debugging to string. * * @return a string */ public String toString() { return "PeriodType[" + getName() + "]"; } //----------------------------------------------------------------------- /** * Gets the indexed field part of the period. * * @param period the period to query * @param index

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> the index to use * @return the value of the field, zero if unsupported */ int getIndexedField(ReadablePeriod period, int index) { int realIndex = iIndices[index]; return (realIndex == -1 ? 0 : period.getValue(realIndex)); } /** * Sets the indexed field part of the period. * * @param period the period to query * @param index the index to use * @param values the array to populate * @param newValue the value to set * @throws UnsupportedOperationException if not supported */ boolean setIndexedField(ReadablePeriod period, int index, int[] values, int newValue) { int realIndex = iIndices[index]; if (realIndex == -1) { throw new UnsupportedOperationException("Field is not supported"); } values[realIndex] = newValue; return true; } /** * Adds to the indexed field part of the period. * * @param period the period to query * @param index the index to use * @param values the array to populate * @param valueToAdd the value to add * @return true if the array is updated * @throws UnsupportedOperationException if not supported */ boolean addIndexedField(ReadablePeriod period, int index, int[] values, int valueToAdd) { if (valueToAdd == 0) { return false; } int realIndex = iIndices[index]; if (realIndex == -1) { throw new UnsupportedOperationException("Field is not supported"); } values[realIndex] = FieldUtils.safeAdd(values[realIndex], valueToAdd); return true; } //----------------------------------------------------------------------- /** * Returns a version of this PeriodType instance that does not support years. * * @return a new period type that supports the original set of fields except years */ public PeriodType withYearsRemoved() { return withFieldRemoved(0, "NoYears"); } /** * Returns a version of this PeriodType instance that does not support months. * * @return a new period type that supports the original set of fields except months */ public PeriodType withMonthsRemoved() { return withFieldRemoved(1, "NoMonths"); } /** * Returns a version of this PeriodType instance that does not support weeks. * * @return a new period type that supports the original set of fields except weeks */ public PeriodType withWeeksRemoved() { return withFieldRemoved(2, "NoWeeks"); } /** * Returns a version of this PeriodType instance that does not support days. * * @return a new period type that supports the original set of fields except days */ public PeriodType withDaysRemoved() { return withFieldRemoved(3, "NoDays"); } /** * Returns a version of this PeriodType instance that does not support hours. * * @return a new period type that supports the original set of fields except hours */ public PeriodType withHoursRemoved() { return withFieldRemoved(4, "NoHours"); }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> /** * Returns a version of this PeriodType instance that does not support minutes. * * @return a new period type that supports the original set of fields except minutes */ public PeriodType withMinutesRemoved() { return withFieldRemoved(5, "NoMinutes"); } /** * Returns a version of this PeriodType instance that does not support seconds. * * @return a new period type that supports the original set of fields except seconds */ public PeriodType withSecondsRemoved() { return withFieldRemoved(6, "NoSeconds"); } /** * Returns a version of this PeriodType instance that does not support milliseconds. * * @return a new period type that supports the original set of fields except milliseconds */ public PeriodType withMillisRemoved() { return withFieldRemoved(7, "NoMillis"); } /** * Removes the field specified by indices index. * * @param indicesIndex the index to remove * @param name the name addition * @return the new type */ private PeriodType withFieldRemoved(int indicesIndex, String name) { int fieldIndex = iIndices[indicesIndex]; if (fieldIndex == -1) { return this; } DurationFieldType[] types = new DurationFieldType[size() - 1]; for (int i = 0; i < iTypes.length; i++) { if (i < fieldIndex) { types[i] = iTypes[i]; } else if (i > fieldIndex) { types[i - 1] = iTypes[i]; } } int[] indices = new int[8]; for (int i = 0; i < indices.length; i++) { if (i < indicesIndex) { indices[i] = iIndices[i]; } else if (i > indicesIndex) { indices[i] = (iIndices[i] == -1 ? -1 : iIndices[i] - 1); } else { indices[i] = -1; } } return new PeriodType(getName() + name, types, indices); } //----------------------------------------------------------------------- /** * Compares this type to another object. * To be equal, the object must be a PeriodType with the same set of fields. * * @param obj the object to compare to * @return true if equal */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof PeriodType == false) { return false; } PeriodType other = (PeriodType) obj; return (Arrays.equals(iTypes, other.iTypes)); } /** * Returns a hashcode based on the field types. * * @return a suitable hashcode */ public int hashCode() { int hash = 0; for (int i = 0; i < iTypes.length; i++) { hash += iTypes[i].hashCode(); } return hash; } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> //----------------------------------------------------------------------- // Design note: Simple accessors return a suitable value, but methods // intended to perform calculations throw an UnsupportedOperationException. public DateTimeFieldType getType() { return iType; } public String getName() { return iType.getName(); } /** * This field is not supported. * * @return false always */ public boolean isSupported() { return false; } /** * This field is not lenient. * * @return false always */ public boolean isLenient() { return false; } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int get(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsText(long instant, Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsText(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsText(ReadablePartial partial, int fieldValue, Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsText(ReadablePartial partial, Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsText(int fieldValue, Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsShortText(long instant, Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsShortText(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsShortText(ReadablePartial partial, int fieldValue, Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsShortText(ReadablePartial partial, Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public String getAsShortText(int fieldValue, Locale locale) { throw unsupported(); } /** * Delegates to the duration field. * * @throws UnsupportedOperationException if the duration is unsupported */ public long add(long instant, int value) { return getDurationField().add(instant, value); } /** * Delegates to the duration field. * * @throws UnsupportedOperationException if the duration is unsupported */ public long add(long instant, long value) { return getDurationField().add(instant, value); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int[] add(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> UnsupportedOperationException */ public int[] addWrapPartial(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long addWrapField(long instant, int value) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { throw unsupported(); } /** * Delegates to the duration field. * * @throws UnsupportedOperationException if the duration is unsupported */ public int getDifference(long minuendInstant, long subtrahendInstant) { return getDurationField().getDifference(minuendInstant, subtrahendInstant); } /** * Delegates to the duration field. * * @throws UnsupportedOperationException if the duration is unsupported */ public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) { return getDurationField().getDifferenceAsLong(minuendInstant, subtrahendInstant); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long set(long instant, int value) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int[] set(ReadablePartial instant, int fieldIndex, int[] values, int newValue) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long set(long instant, String text, Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long set(long instant, String text) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int[] set(ReadablePartial instant, int fieldIndex, int[] values, String text, Locale locale) { throw unsupported(); } /** * Even though this DateTimeField is unsupported, the duration field might * be supported. * * @return a possibly supported DurationField */ public DurationField getDurationField() { return iDurationField; } /** * Always returns null. * * @return null always */ public DurationField getRangeDurationField() { return null; } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public boolean isLeap(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getLeapAmount(long instant) { throw unsupported(); } /** * Always returns null. * * @return null always */ public DurationField getLeapDurationField() { return null; } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMinimumValue() { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int get

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>MinimumValue(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMinimumValue(ReadablePartial instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMinimumValue(ReadablePartial instant, int[] values) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMaximumValue() { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMaximumValue(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMaximumValue(ReadablePartial instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMaximumValue(ReadablePartial instant, int[] values) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMaximumTextLength(Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public int getMaximumShortTextLength(Locale locale) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long roundFloor(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long roundCeiling(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long roundHalfFloor(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long roundHalfCeiling(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long roundHalfEven(long instant) { throw unsupported(); } /** * Always throws UnsupportedOperationException * * @throws UnsupportedOperationException */ public long remainder(long instant) { throw unsupported(); } //------------------------------------------------------------------------ /** * Get a suitable debug string. * * @return debug string */ public String toString() { return "UnsupportedDateTimeField"; } /** * Ensure proper singleton serialization */ private Object readResolve() { return getInstance(iType, iDurationField); } private UnsupportedOperationException unsupported() { return new UnsupportedOperationException(iType + " field is unsupported"); } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2009 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time.chrono; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import org.joda.time.Chronology; import org.joda.time.DateTimeFieldType; import org.joda.time.DateTimeZone; import org.joda.time.field.DividedDateTimeField; import org.joda.time.field.RemainderDateTimeField; /** * Implements a chronology that follows the rules of the ISO8601 standard, * which is compatible with Gregorian for all modern dates. * When ISO does not define a field, but it can be determined (such as AM/PM) * it is included. * <p> * With the exception of century related fields, ISOChronology is exactly the * same as {@link GregorianChronology}. In this chronology, centuries and year * of century are zero based. For all years, the century is determined by * dropping the last two digits of the year, ignoring sign. The year of century * is the value of the last two year digits. * <p> * ISOChronology is thread-safe and immutable. * * @author Stephen Colebourne * @author Brian S O'Neill * @since 1.0 */ public final class ISOChronology extends AssembledChronology { /** Serialization lock */ private static final long serialVersionUID = -6212696554273812441L; /** Singleton instance of a UTC ISOChronology */ private static final ISOChronology INSTANCE_UTC; private static final int FAST_CACHE_SIZE = 64; /** Fast cache of zone to chronology */ private static final ISOChronology[] cFastCache; /** Cache of zone to chronology */ private static final Map<DateTimeZone, ISOChronology> cCache = new HashMap<DateTimeZone, ISOChronology>(); static { cFastCache = new ISOChronology[FAST_CACHE_SIZE]; INSTANCE_UTC = new ISOChronology(GregorianChronology.getInstanceUTC()); c

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>Cache.put(DateTimeZone.UTC, INSTANCE_UTC); } /** * Gets an instance of the ISOChronology. * The time zone of the returned instance is UTC. * * @return a singleton UTC instance of the chronology */ public static ISOChronology getInstanceUTC() { return INSTANCE_UTC; } /** * Gets an instance of the ISOChronology in the default time zone. * * @return a chronology in the default time zone */ public static ISOChronology getInstance() { return getInstance(DateTimeZone.getDefault()); } /** * Gets an instance of the ISOChronology in the given time zone. * * @param zone the time zone to get the chronology in, null is default * @return a chronology in the specified time zone */ public static ISOChronology getInstance(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } int index = System.identityHashCode(zone) & (FAST_CACHE_SIZE - 1); ISOChronology chrono = cFastCache[index]; if (chrono != null && chrono.getZone() == zone) { return chrono; } synchronized (cCache) { chrono = cCache.get(zone); if (chrono == null) { chrono = new ISOChronology(ZonedChronology.getInstance(INSTANCE_UTC, zone)); cCache.put(zone, chrono); } } cFastCache[index] = chrono; return chrono; } // Constructors and instance variables //----------------------------------------------------------------------- /** * Restricted constructor */ private ISOChronology(Chronology base) { super(base, null); } // Conversion //----------------------------------------------------------------------- /** * Gets the Chronology in the UTC time zone. * * @return the chronology in UTC */ public Chronology withUTC() { return INSTANCE_UTC; } /** * Gets the Chronology in a specific time zone. * * @param zone the zone to get the chronology in, null is default * @return the chronology */ public Chronology withZone(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } if (zone == getZone()) { return this; } return getInstance(zone); } // Output //----------------------------------------------------------------------- /** * Gets a debugging toString. * * @return a debugging string */ public String toString() { String str = "ISOChronology"; DateTimeZone zone = getZone(); if (zone != null) { str = str + '[' + zone.getID() + ']'; } return str; } protected void assemble(Fields fields) { if (getBase().getZone() == DateTimeZone.UTC) { // Use zero based century and year of century. fields.centuryOfEra = new DividedDateTimeField( ISOYearOfEraDateTimeField.

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>INSTANCE, DateTimeFieldType.centuryOfEra(), 100); fields.yearOfCentury = new RemainderDateTimeField( (DividedDateTimeField) fields.centuryOfEra, DateTimeFieldType.yearOfCentury()); fields.weekyearOfCentury = new RemainderDateTimeField( (DividedDateTimeField) fields.centuryOfEra, DateTimeFieldType.weekyearOfCentury()); fields.centuries = fields.centuryOfEra.getDurationField(); } } /** * Checks if this chronology instance equals another. * * @param obj the object to compare to * @return true if equal * @since 1.6 */ public boolean equals(Object obj) { return super.equals(obj); } /** * A suitable hash code for the chronology. * * @return the hash code * @since 1.6 */ public int hashCode() { return "ISO".hashCode() * 11 + getZone().hashCode(); } /** * Serialize ISOChronology instances using a small stub. This reduces the * serialized size, and deserialized instances come from the cache. */ private Object writeReplace() { return new Stub(getZone()); } private static final class Stub implements Serializable { private static final long serialVersionUID = -6212696554273812441L; private transient DateTimeZone iZone; Stub(DateTimeZone zone) { iZone = zone; } private Object readResolve() { return ISOChronology.getInstance(iZone); } private void writeObject(ObjectOutputStream out) throws IOException { out.writeObject(iZone); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { iZone = (DateTimeZone)in.readObject(); } } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>/* * Copyright 2001-2005 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.joda.time.field; import org.joda.time.DateTimeField; import org.joda.time.DateTimeFieldType; import org.joda.time.DurationField; import org.joda.time.ReadablePartial; /** * Wraps another field such that zero values are replaced with one more than * it's maximum. This is particularly useful for implementing an clockhourOfDay * field, where the midnight value of 0 is replaced with 24. * <p> * ZeroIsMaxDateTimeField is thread-safe and immutable. * * @author Brian S O'Neill * @since 1.0 */ public final class ZeroIsMaxDateTimeField extends DecoratedDateTimeField { private static final long serialVersionUID = 961749798233026866L; /** * Constructor. * * @param field the base field * @param type the field type this field will actually use * @throws IllegalArgumentException if wrapped field's minimum value is not zero */ public ZeroIsMaxDateTimeField(DateTimeField field, DateTimeFieldType type) { super(field, type); if (field.getMinimumValue() != 0) { throw new IllegalArgumentException("Wrapped field's minumum value must be zero"); } } public int get(long instant) { int value = getWrappedField().get(instant); if (value == 0) { value = getMaximumValue(); } return value; } public long add(long instant, int value) { return getWrappedField().add(instant, value); } public long add(long instant, long value) { return getWrappedField().add(instant, value); } public long addWrapField(long instant, int value) { return getWrappedField().addWrapField(instant, value); } public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { return getWrappedField().addWrapField(instant, fieldIndex, values, valueToAdd); } public int getDifference(long minuendInstant, long subtrahendInstant) { return getWrappedField().getDifference(minuendInstant, subtrahendInstant); } public long getDifferenceAsLong(long minuendInstant, long subtrah

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>endInstant) { return getWrappedField().getDifferenceAsLong(minuendInstant, subtrahendInstant); } public long set(long instant, int value) { int max = getMaximumValue(); FieldUtils.verifyValueBounds(this, value, 1, max); if (value == max) { value = 0; } return getWrappedField().set(instant, value); } public boolean isLeap(long instant) { return getWrappedField().isLeap(instant); } public int getLeapAmount(long instant) { return getWrappedField().getLeapAmount(instant); } public DurationField getLeapDurationField() { return getWrappedField().getLeapDurationField(); } /** * Always returns 1. * * @return the minimum value of 1 */ public int getMinimumValue() { return 1; } /** * Always returns 1. * * @return the minimum value of 1 */ public int getMinimumValue(long instant) { return 1; } /** * Always returns 1. * * @return the minimum value of 1 */ public int getMinimumValue(ReadablePartial instant) { return 1; } /** * Always returns 1. * * @return the minimum value of 1 */ public int getMinimumValue(ReadablePartial instant, int[] values) { return 1; } /** * Get the maximum value for the field, which is one more than the wrapped * field's maximum value. * * @return the maximum value */ public int getMaximumValue() { return getWrappedField().getMaximumValue() + 1; } /** * Get the maximum value for the field, which is one more than the wrapped * field's maximum value. * * @return the maximum value */ public int getMaximumValue(long instant) { return getWrappedField().getMaximumValue(instant) + 1; } /** * Get the maximum value for the field, which is one more than the wrapped * field's maximum value. * * @return the maximum value */ public int getMaximumValue(ReadablePartial instant) { return getWrappedField().getMaximumValue(instant) + 1; } /** * Get the maximum value for the field, which is one more than the wrapped * field's maximum value. * * @return the maximum value */ public int getMaximumValue(ReadablePartial instant, int[] values) { return getWrappedField().getMaximumValue(instant, values) + 1; } public long roundFloor(long instant) { return getWrappedField().roundFloor(instant); } public long roundCeiling(long instant) { return getWrappedField().roundCeiling(instant); } public long roundHalfFloor(long instant) { return getWrappedField().roundHalfFloor(instant); } public long roundHalfCeiling(long

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> thisMonth = iChronology.getMonthOfYear(instant, thisYear); long yearToUse; long monthToUse = thisMonth - 1 + months; if (monthToUse >= 0) { yearToUse = thisYear + (monthToUse / iMax); monthToUse = (monthToUse % iMax) + 1; } else { yearToUse = thisYear + (monthToUse / iMax) - 1; monthToUse = Math.abs(monthToUse); int remMonthToUse = (int)(monthToUse % iMax); if (remMonthToUse == 0) { remMonthToUse = iMax; } monthToUse = iMax - remMonthToUse + 1; if (monthToUse == 1) { yearToUse += 1; } } if (yearToUse < iChronology.getMinYear() || yearToUse > iChronology.getMaxYear()) { throw new IllegalArgumentException ("Magnitude of add amount is too large: " + months); } int i_yearToUse = (int)yearToUse; int i_monthToUse = (int)monthToUse; int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth); int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse); if (dayToUse > maxDay) { dayToUse = maxDay; } long datePart = iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse); return datePart + timePart; } //----------------------------------------------------------------------- public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) { // overridden as superclass algorithm can't handle // 2004-02-29 + 48 months -> 2008-02-29 type dates if (valueToAdd == 0) { return values; } if (DateTimeUtils.isContiguous(partial)) { long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]); } instant = add(instant, valueToAdd); return iChronology.get(partial, instant); } else { return super.add(partial, fieldIndex, values, valueToAdd); } } //----------------------------------------------------------------------- /** * Add to the Month component of the specified time instant * wrapping around within that component if necessary. * * @see org.joda.time.DateTimeField#addWrapField * @param instant the time instant in millis to update. * @param months the months to add (can be negative). * @return the updated time instant. */ public long addWrapField(long instant, int months) { return set(instant, FieldUtils.getWrappedValue(get(instant), months, MIN, iMax)); } //-----------------------------------------------------------------------

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> static final GregorianChronology INSTANCE_UTC; /** Cache of zone to chronology arrays */ private static final Map<DateTimeZone, GregorianChronology[]> cCache = new HashMap<DateTimeZone, GregorianChronology[]>(); static { INSTANCE_UTC = getInstance(DateTimeZone.UTC); } /** * Gets an instance of the GregorianChronology. * The time zone of the returned instance is UTC. * * @return a singleton UTC instance of the chronology */ public static GregorianChronology getInstanceUTC() { return INSTANCE_UTC; } /** * Gets an instance of the GregorianChronology in the default time zone. * * @return a chronology in the default time zone */ public static GregorianChronology getInstance() { return getInstance(DateTimeZone.getDefault(), 4); } /** * Gets an instance of the GregorianChronology in the given time zone. * * @param zone the time zone to get the chronology in, null is default * @return a chronology in the specified time zone */ public static GregorianChronology getInstance(DateTimeZone zone) { return getInstance(zone, 4); } /** * Gets an instance of the GregorianChronology in the given time zone. * * @param zone the time zone to get the chronology in, null is default * @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4 * @return a chronology in the specified time zone */ public static GregorianChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek) { if (zone == null) { zone = DateTimeZone.getDefault(); } GregorianChronology chrono; synchronized (cCache) { GregorianChronology[] chronos = cCache.get(zone); if (chronos == null) { chronos = new GregorianChronology[7]; cCache.put(zone, chronos); } try { chrono = chronos[minDaysInFirstWeek - 1]; } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException ("Invalid min days in first week: " + minDaysInFirstWeek); } if (chrono == null) { if (zone == DateTimeZone.UTC) { chrono = new GregorianChronology(null, null, minDaysInFirstWeek); } else { chrono = getInstance(DateTimeZone.UTC, minDaysInFirstWeek); chrono = new GregorianChronology (ZonedChronology.getInstance(chrono, zone), null, minDaysInFirstWeek); } chronos[minDaysInFirstWeek - 1] = chrono; } } return chrono; } // Constructors and instance variables //----------------------------------------------------------------------- /** * Restricted constructor */ private GregorianChronology(Chronology base, Object param, int minDaysInFirstWeek) { super(base, param, minDaysIn

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> add to * @param value the long value to add, in the units of the field * @return the updated milliseconds * @throws IllegalArgumentException if value is too large * @see #add(long,int) */ public abstract long add(long instant, long value); /** * Adds a value (which may be negative) to the partial instant, * throwing an exception if the maximum size of the instant is reached. * <p> * The value will be added to this field, overflowing into larger fields * if necessary. Smaller fields should be unaffected, except where the * result would be an invalid value for a smaller field. In this case the * smaller field is adjusted to be in range. * <p> * Partial instants only contain some fields. This may result in a maximum * possible value, such as TimeOfDay being limited to 23:59:59:999. If this * limit is breached by the add an exception is thrown. * <p> * For example, in the ISO chronology:<br> * 2000-08-20 add six months is 2000-02-20<br> * 2000-08-20 add twenty months is 2000-04-20<br> * 2000-08-20 add minus nine months is 2000-11-20<br> * 2001-01-31 add one month is 2001-02-28<br> * 2001-01-31 add two months is 2001-03-31<br> * * @param instant the partial instant * @param fieldIndex the index of this field in the instant * @param values the values of the partial instant which should be updated * @param valueToAdd the value to add, in the units of the field * @return the passed in values * @throws IllegalArgumentException if the value is invalid or the maximum instant is reached */ public abstract int[] add(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd); /** * Adds a value (which may be negative) to the partial instant, * wrapping the whole partial if the maximum size of the partial is reached. * <p> * The value will be added to this field, overflowing into larger fields * if necessary. Smaller fields should be unaffected, except where the * result would be an invalid value for a smaller field. In this case the * smaller field is adjusted to be in range. * <p> * Partial instants only contain some fields. This may result in a maximum * possible value, such as TimeOfDay normally being limited to 23:59:59:999. * If ths limit is reached by the addition, this method will wrap back to * 00:00:00.0

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>00. In fact, you would generally only use this method for * classes that have a limitation such as this. * <p> * For example, in the ISO chronology:<br> * 10:20:30 add 20 minutes is 10:40:30<br> * 10:20:30 add 45 minutes is 11:05:30<br> * 10:20:30 add 16 hours is 02:20:30<br> * * @param instant the partial instant * @param fieldIndex the index of this field in the partial * @param values the values of the partial instant which should be updated * @param valueToAdd the value to add, in the units of the field * @return the passed in values * @throws IllegalArgumentException if the value is invalid or the maximum instant is reached */ public abstract int[] addWrapPartial(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd); /** * Adds a value (which may be negative) to the millis value, * wrapping within this field. * <p> * The value will be added to this field. If the value is too large to be * added solely to this field then it wraps. Larger fields are always * unaffected. Smaller fields should be unaffected, except where the * result would be an invalid value for a smaller field. In this case the * smaller field is adjusted to be in range. * <p> * For example, in the ISO chronology:<br> * 2000-08-20 addWrapField six months is 2000-02-20<br> * 2000-08-20 addWrapField twenty months is 2000-04-20<br> * 2000-08-20 addWrapField minus nine months is 2000-11-20<br> * 2001-01-31 addWrapField one month is 2001-02-28<br> * 2001-01-31 addWrapField two months is 2001-03-31<br> * * @param instant the milliseconds from 1970-01-01T00:00:00Z to add to * @param value the value to add, in the units of the field * @return the updated milliseconds */ public abstract long addWrapField(long instant, int value) ; /** * Adds a value (which may be negative) to the partial instant, * wrapping within this field. * <p> * The value will be added to this field. If the value is too large to be * added solely to this field then it wraps. Larger fields are always * unaffected. Small

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>er fields should be unaffected, except where the * result would be an invalid value for a smaller field. In this case the * smaller field is adjusted to be in range. * <p> * For example, in the ISO chronology:<br> * 2000-08-20 addWrapField six months is 2000-02-20<br> * 2000-08-20 addWrapField twenty months is 2000-04-20<br> * 2000-08-20 addWrapField minus nine months is 2000-11-20<br> * 2001-01-31 addWrapField one month is 2001-02-28<br> * 2001-01-31 addWrapField two months is 2001-03-31<br> * * @param instant the partial instant * @param fieldIndex the index of this field in the instant * @param values the values of the partial instant which should be updated * @param valueToAdd the value to add, in the units of the field * @return the passed in values * @throws IllegalArgumentException if the value is invalid */ public abstract int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd); /** * Computes the difference between two instants, as measured in the units * of this field. Any fractional units are dropped from the result. Calling * getDifference reverses the effect of calling add. In the following code: * * <pre> * long instant = ... * int v = ... * int age = getDifference(add(instant, v), instant); * </pre> * * The value 'age' is the same as the value 'v'. * * @param minuendInstant the milliseconds from 1970-01-01T00:00:00Z to * subtract from * @param subtrahendInstant the milliseconds from 1970-01-01T00:00:00Z to * subtract off the minuend * @return the difference in the units of this field */ public abstract int getDifference(long minuendInstant, long subtrahendInstant); /** * Computes the difference between two instants, as measured in the units * of this field. Any fractional units are dropped from the result. Calling * getDifference reverses the effect of calling add. In the following code: * * <pre> * long instant = ... * long v = ... * long age = getDifferenceAsLong(add(instant, v), instant); * </pre> * * The value 'age' is the same as the value 'v'. * * @param minuendInstant the milliseconds from 1970-0

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>1-01T00:00:00Z to * subtract from * @param subtrahendInstant the milliseconds from 1970-01-01T00:00:00Z to * subtract off the minuend * @return the difference in the units of this field */ public abstract long getDifferenceAsLong(long minuendInstant, long subtrahendInstant); /** * Sets a value in the milliseconds supplied. * <p> * The value of this field will be set. * If the value is invalid, an exception if thrown. * <p> * If setting this field would make other fields invalid, then those fields * may be changed. For example if the current date is the 31st January, and * the month is set to February, the day would be invalid. Instead, the day * would be changed to the closest value - the 28th/29th February as appropriate. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to set in * @param value the value to set, in the units of the field * @return the updated milliseconds * @throws IllegalArgumentException if the value is invalid */ public abstract long set(long instant, int value); /** * Sets a value using the specified partial instant. * <p> * The value of this field (specified by the index) will be set. * If the value is invalid, an exception if thrown. * <p> * If setting this field would make other fields invalid, then those fields * may be changed. For example if the current date is the 31st January, and * the month is set to February, the day would be invalid. Instead, the day * would be changed to the closest value - the 28th/29th February as appropriate. * * @param instant the partial instant * @param fieldIndex the index of this field in the instant * @param values the values of the partial instant which should be updated * @param newValue the value to set, in the units of the field * @return the passed in values * @throws IllegalArgumentException if the value is invalid */ public abstract int[] set(ReadablePartial instant, int fieldIndex, int[] values, int newValue); /** * Sets a value in the milliseconds supplied from a human-readable, text value. * If the specified locale is null, the default locale is used. * <p> * If setting this field would make other fields invalid, then those fields * may be changed. For example if the current date is the 31st January, and * the month is set to February, the day would be invalid. Instead, the day * would be changed to the closest value - the 28th/29th February as appropriate. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to set

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> in * @param text the text value to set * @param locale the locale to use for selecting a text symbol, null for default * @return the updated milliseconds * @throws IllegalArgumentException if the text value is invalid */ public abstract long set(long instant, String text, Locale locale); /** * Sets a value in the milliseconds supplied from a human-readable, text value. * <p> * If setting this field would make other fields invalid, then those fields * may be changed. For example if the current date is the 31st January, and * the month is set to February, the day would be invalid. Instead, the day * would be changed to the closest value - the 28th/29th February as appropriate. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to set in * @param text the text value to set * @return the updated milliseconds * @throws IllegalArgumentException if the text value is invalid */ public abstract long set(long instant, String text); /** * Sets a value in the milliseconds supplied from a human-readable, text value. * If the specified locale is null, the default locale is used. * <p> * If setting this field would make other fields invalid, then those fields * may be changed. For example if the current date is the 31st January, and * the month is set to February, the day would be invalid. Instead, the day * would be changed to the closest value - the 28th/29th February as appropriate. * * @param instant the partial instant * @param fieldIndex the index of this field in the instant * @param values the values of the partial instant which should be updated * @param text the text value to set * @param locale the locale to use for selecting a text symbol, null for default * @return the passed in values * @throws IllegalArgumentException if the text value is invalid */ public abstract int[] set(ReadablePartial instant, int fieldIndex, int[] values, String text, Locale locale); // Extra information API //------------------------------------------------------------------------ /** * Returns the duration per unit value of this field. For example, if this * field represents "hour of day", then the duration is an hour. * * @return the duration of this field, or UnsupportedDurationField if field * has no duration */ public abstract DurationField getDurationField(); /** * Returns the range duration of this field. For example, if this field * represents "hour of day", then the range duration is a day. * * @return the range duration of this field, or null if field has no range */ public abstract DurationField getRangeDurationField(); /** * Returns whether this field is 'leap' for the specified instant. * <p> * For example, a leap year would return true, a non leap year would return * false. * * @param instant the instant to check for leap status

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * @return true if the field is 'leap' */ public abstract boolean isLeap(long instant); /** * Gets the amount by which this field is 'leap' for the specified instant. * <p> * For example, a leap year would return one, a non leap year would return * zero. * * @param instant the instant to check for leap status * @return the amount, in units of the leap duration field, that the field is leap */ public abstract int getLeapAmount(long instant); /** * If this field were to leap, then it would be in units described by the * returned duration. If this field doesn't ever leap, null is returned. * * @return the leap duration field if field can be leap, null if it can't */ public abstract DurationField getLeapDurationField(); /** * Get the minimum allowable value for this field. * * @return the minimum valid value for this field, in the units of the * field */ public abstract int getMinimumValue(); /** * Get the minimum value for this field evaluated at the specified time. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to query * @return the minimum value for this field, in the units of the field */ public abstract int getMinimumValue(long instant); /** * Get the minimum value for this field evaluated at the specified time. * * @param instant the partial instant to query * @return the minimum value for this field, in the units of the field */ public abstract int getMinimumValue(ReadablePartial instant); /** * Get the minimum value for this field using the partial instant and * the specified values. * * @param instant the partial instant to query * @param values the values to use * @return the minimum value for this field, in the units of the field */ public abstract int getMinimumValue(ReadablePartial instant, int[] values); /** * Get the maximum allowable value for this field. * * @return the maximum valid value for this field, in the units of the * field */ public abstract int getMaximumValue(); /** * Get the maximum value for this field evaluated at the specified time. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to query * @return the maximum value for this field, in the units of the field */ public abstract int getMaximumValue(long instant); /** * Get the maximum value for this field evaluated at the specified time. * * @param instant the partial instant to query * @return the maximum value for this field, in the units of the field */ public abstract int getMaximumValue(ReadablePartial instant); /** * Get the maximum value for this field using the partial instant and * the specified values. * * @param instant

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> the partial instant to query * @param values the values to use * @return the maximum value for this field, in the units of the field */ public abstract int getMaximumValue(ReadablePartial instant, int[] values); /** * Get the maximum text value for this field. * * @param locale the locale to use for selecting a text symbol * @return the maximum text length */ public abstract int getMaximumTextLength(Locale locale); /** * Get the maximum short text value for this field. * * @param locale the locale to use for selecting a text symbol * @return the maximum short text length */ public abstract int getMaximumShortTextLength(Locale locale); // Calculation API //------------------------------------------------------------------------ /** * Round to the lowest whole unit of this field. After rounding, the value * of this field and all fields of a higher magnitude are retained. The * fractional millis that cannot be expressed in whole increments of this * field are set to minimum. * <p> * For example, a datetime of 2002-11-02T23:34:56.789, rounded to the * lowest whole hour is 2002-11-02T23:00:00.000. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to round * @return rounded milliseconds */ public abstract long roundFloor(long instant); /** * Round to the highest whole unit of this field. The value of this field * and all fields of a higher magnitude may be incremented in order to * achieve this result. The fractional millis that cannot be expressed in * whole increments of this field are set to minimum. * <p> * For example, a datetime of 2002-11-02T23:34:56.789, rounded to the * highest whole hour is 2002-11-03T00:00:00.000. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to round * @return rounded milliseconds */ public abstract long roundCeiling(long instant); /** * Round to the nearest whole unit of this field. If the given millisecond * value is closer to the floor or is exactly halfway, this function * behaves like roundFloor. If the millisecond value is closer to the * ceiling, this function behaves like roundCeiling. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to round * @return rounded milliseconds */ public abstract long roundHalfFloor(long instant); /** * Round to the nearest whole unit of this field. If the given millisecond * value is closer to the floor, this function behaves like roundFloor

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> * * @return the interval as an Interval object */ Interval toInterval(); /** * Get this time interval as a <code>MutableInterval</code>. * <p> * This will always return a new <code>MutableInterval</code> with the same interval. * * @return the time interval as a MutableInterval object */ MutableInterval toMutableInterval(); //----------------------------------------------------------------------- /** * Gets the millisecond duration of this time interval. * * @return the millisecond duration of the time interval * @throws ArithmeticException if the duration exceeds the capacity of a long */ Duration toDuration(); /** * Gets the millisecond duration of this time interval. * * @return the millisecond duration of the time interval * @throws ArithmeticException if the duration exceeds the capacity of a long */ long toDurationMillis(); /** * Converts the duration of the interval to a period using the * standard period type. * <p> * This method should be used to exract the field values describing the * difference between the start and end instants. * * @return a time period derived from the interval */ Period toPeriod(); /** * Converts the duration of the interval to a period using the * specified period type. * <p> * This method should be used to exract the field values describing the * difference between the start and end instants. * * @param type the requested type of the duration, null means standard * @return a time period derived from the interval */ Period toPeriod(PeriodType type); //----------------------------------------------------------------------- /** * Compares this object with the specified object for equality based * on start and end millis plus the chronology. * All ReadableInterval instances are accepted. * <p> * To compare the duration of two time intervals, use {@link #toDuration()} * to get the durations and compare those. * * @param readableInterval a readable interval to check against * @return true if the start and end millis are equal */ boolean equals(Object readableInterval); /** * Gets a hash code for the time interval that is compatable with the * equals method. * <p> * The formula used must be as follows: * <pre>int result = 97; * result = 31 * result + ((int) (getStartMillis() ^ (getStartMillis() >>> 32))); * result = 31 * result + ((int) (getEndMillis() ^ (getEndMillis() >>> 32))); * result = 31 * result + getChronology().hashCode(); * return result;</pre> * * @return a hash code */ int hashCode(); //----------------------------------------------------------------------- /** * Get the value as a String in the ISO8601 interval format. * <p> * For example, "2004-06-09T12:30:00.000/2004-07-10T13:30:00

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>Instant start, ReadableInstant end) { super(); if (start == end) { iMillis = 0L; } else { long startMillis = DateTimeUtils.getInstantMillis(start); long endMillis = DateTimeUtils.getInstantMillis(end); iMillis = FieldUtils.safeAdd(endMillis, -startMillis); } } /** * Creates a duration from the specified object using the * {@link org.joda.time.convert.ConverterManager ConverterManager}. * * @param duration duration to convert * @throws IllegalArgumentException if duration is invalid */ protected BaseDuration(Object duration) { super(); DurationConverter converter = ConverterManager.getInstance().getDurationConverter(duration); iMillis = converter.getDurationMillis(duration); } //----------------------------------------------------------------------- /** * Gets the length of this duration in milliseconds. * * @return the length of the duration in milliseconds. */ public long getMillis() { return iMillis; } //----------------------------------------------------------------------- /** * Sets the length of this duration in milliseconds. * * @param duration the new length of the duration */ protected void setMillis(long duration) { iMillis = duration; } //----------------------------------------------------------------------- /** * Converts this duration to a Period instance using the specified period type * and the ISO chronology. * <p> * Only precise fields in the period type will be used. * At most these are hours, minutes, seconds and millis - the period * type may restrict the selection further. * <p> * For more control over the conversion process, you must pair the duration with * an instant, see {@link #toPeriodFrom(ReadableInstant, PeriodType)}. * * @param type the period type to use, null means standard * @return a Period created using the millisecond duration from this instance */ public Period toPeriod(PeriodType type) { return new Period(getMillis(), type); } /** * Converts this duration to a Period instance using the standard period type * and the specified chronology. * <p> * Only precise fields in the period type will be used. * Exactly which fields are precise depends on the chronology. * Only the time fields are precise for ISO chronology with a time zone. * However, ISO UTC also has precise days and weeks. * <p> * For more control over the conversion process, you must pair the duration with * an instant, see {@link #toPeriodFrom(ReadableInstant)} and * {@link #toPeriodTo(ReadableInstant)} * * @param chrono the chronology to use, null means ISO default * @return a Period created using the millisecond duration from this instance */ public Period toPeriod(Chronology chrono) { return new Period(getMillis(), chrono); } /** * Converts this duration to a Period instance using the specified period type * and chronology. * <p> * Only precise fields in the period type will be used. * Exactly which fields are precise depends

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> on the chronology. * Only the time fields are precise for ISO chronology with a time zone. * However, ISO UTC also has precise days and weeks. * <p> * For more control over the conversion process, you must pair the duration with * an instant, see {@link #toPeriodFrom(ReadableInstant, PeriodType)} and * {@link #toPeriodTo(ReadableInstant, PeriodType)} * * @param type the period type to use, null means standard * @param chrono the chronology to use, null means ISO default * @return a Period created using the millisecond duration from this instance */ public Period toPeriod(PeriodType type, Chronology chrono) { return new Period(getMillis(), type, chrono); } /** * Converts this duration to a Period instance by adding the duration to a start * instant to obtain an interval using the standard period type. * <p> * This conversion will determine the fields of a period accurately. * The results are based on the instant millis, the chronology of the instant, * the standard period type and the length of this duration. * * @param startInstant the instant to calculate the period from, null means now * @return a Period created using the millisecond duration from this instance */ public Period toPeriodFrom(ReadableInstant startInstant) { return new Period(startInstant, this); } /** * Converts this duration to a Period instance by adding the duration to a start * instant to obtain an interval. * <p> * This conversion will determine the fields of a period accurately. * The results are based on the instant millis, the chronology of the instant, * the period type and the length of this duration. * * @param startInstant the instant to calculate the period from, null means now * @param type the period type determining how to split the duration into fields, null means All type * @return a Period created using the millisecond duration from this instance */ public Period toPeriodFrom(ReadableInstant startInstant, PeriodType type) { return new Period(startInstant, this, type); } /** * Converts this duration to a Period instance by subtracting the duration * from an end instant to obtain an interval using the standard period * type. * <p> * This conversion will determine the fields of a period accurately. * The results are based on the instant millis, the chronology of the instant, * the standard period type and the length of this duration. * * @param endInstant the instant to calculate the period to, null means now * @return a Period created using the millisecond duration from this instance */ public Period toPeriodTo(ReadableInstant endInstant) { return new Period(this, endInstant); } /** * Converts this duration to a Period instance by subtracting the duration * from an end instant to obtain an interval using the standard period * type. * <p> * This conversion will determine the fields of a period accurately. * The results

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS> are based on the instant millis, the chronology of the instant, * the period type and the length of this duration. * * @param endInstant the instant to calculate the period to, null means now * @param type the period type determining how to split the duration into fields, null means All type * @return a Period created using the millisecond duration from this instance */ public Period toPeriodTo(ReadableInstant endInstant, PeriodType type) { return new Period(this, endInstant, type); } /** * Converts this duration to an Interval starting at the specified instant. * * @param startInstant the instant to start the interval at, null means now * @return an Interval starting at the specified instant */ public Interval toIntervalFrom(ReadableInstant startInstant) { return new Interval(startInstant, this); } /** * Converts this duration to an Interval ending at the specified instant. * * @param endInstant the instant to end the interval at, null means now * @return an Interval ending at the specified instant */ public Interval toIntervalTo(ReadableInstant endInstant) { return new Interval(this, endInstant); } }

Time, 22

<FILEB>
<CHANGES>
super();
<CHANGEE>
<CHANGES>
iType = PeriodType.time();
int[] values = ISOChronology.getInstanceUTC().get(this, duration);
iType = PeriodType.standard();
iValues = new int[8];
System.arraycopy(values, 0, iValues, 4, 4);
<CHANGEE>
<FILEE>
<FILEB> super(); type = checkPeriodType(type); long durationMillis = DateTimeUtils.getDurationMillis(duration); long endMillis = DateTimeUtils.getInstantMillis(endInstant); long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis); Chronology chrono = DateTimeUtils.getInstantChronology(endInstant); iType = type; iValues = chrono.get(this, startMillis, endMillis); } /** * Creates a period from the given millisecond duration with the standard period type * and ISO rules, ensuring that the calculation is performed with the time-only period type. * <p> * The calculation uses the hour, minute, second and millisecond fields. * * @param duration the duration, in milliseconds */ protected BasePeriod(long duration) { <CHANGES> this(duration, null, null); <CHANGEE> // bug [3264409] <CHANGES> <CHANGEE> } /** * Creates a period from the given millisecond duration, which is only really * suitable for durations less than one day. * <p> * Only fields that are precise will be used. * Thus the largest precise field may have a large value. * * @param duration the duration, in milliseconds * @param type which set of fields this period supports, null means standard * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period type is invalid <FILEE> <SCANS>EraDateTimeField("AM"); /** The lowest year that can be fully supported. */ private static final int MIN_YEAR = -292269337; /** The highest year that can be fully supported. */ private static final int MAX_YEAR = 292272708; /** Cache of zone to chronology arrays */ private static final Map<DateTimeZone, CopticChronology[]> cCache = new HashMap<DateTimeZone, CopticChronology[]>(); /** Singleton instance of a UTC CopticChronology */ private static final CopticChronology INSTANCE_UTC; static { // init after static fields INSTANCE_UTC = getInstance(DateTimeZone.UTC); } //----------------------------------------------------------------------- /** * Gets an instance of the CopticChronology. * The time zone of the returned instance is UTC. * * @return a singleton UTC instance of the chronology */ public static CopticChronology getInstanceUTC() { return INSTANCE_UTC; } /** * Gets an instance of the CopticChronology in the default time zone. * * @return a chronology in the default time zone */ public static CopticChronology getInstance() { return getInstance(DateTimeZone.getDefault(), 4); } /** * Gets an instance of the CopticChronology in the given time zone. * * @param zone the time zone to get the chronology in, null is default * @return a chronology in the specified time zone */ public static CopticChronology getInstance(DateTimeZone zone) { return getInstance(zone, 4); } /** * Gets an instance of the CopticChronology in the given time zone. * * @param zone the time zone to get the chronology in, null is default * @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4 * @return a chronology in the specified time zone */ public static CopticChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek) { if (zone == null) { zone = DateTimeZone.getDefault(); } CopticChronology chrono; synchronized (cCache) { CopticChronology[] chronos = cCache.get(zone); if (chronos == null) { chronos = new CopticChronology[7]; cCache.put(zone, chronos); } try { chrono = chronos[minDaysInFirstWeek - 1]; } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException ("Invalid min days in first week: " + minDaysInFirstWeek); } if (chrono == null) { if (zone == DateTimeZone.UTC) { // First create without a lower limit. chrono = new CopticChronology(null, null, minDaysInFirstWeek); // Impose lower limit and make another Coptic